﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using TGServer;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace MyWebServer
{
    public class Peer : PeerBase

    {
        public Player player=new Player();
        public Userinfo userinfo=new Userinfo();
        public Room room = null;
        public Desk joinDesk = null;
        public int test_number=0;
        public GameState gamestate = GameState.login;
        //public Desk desk = null;
        /// <summary>
        /// 当客户端断开连接时
        /// </summary>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        public override void OnDisConnected(Exception e)
        {
            Desk desk = new Desk();
            if (room != null)
            {
                if (room.desk_dong.peer != null)
                {
                    if (player.playerPos == room.desk_dong.peer.player.playerPos)
                    {
                        desk = room.desk_dong;
                    }
                }
                else if (room.desk_nan.peer != null)
                {
                    if (player.playerPos == room.desk_nan.peer.player.playerPos)
                    {
                        desk = room.desk_nan;
                    }
                }
                else if (room.desk_xi.peer != null)
                {
                    if (player.playerPos == room.desk_xi.peer.player.playerPos)
                    {
                        desk = room.desk_xi;
                    }
                }
                else if (room.desk_bei != null)
                {
                    if (player.playerPos == room.desk_bei.peer.player.playerPos)
                    {
                        desk = room.desk_bei;
                    }
                }









                Console.WriteLine("OnDisConnected:掉线原因是：" + e.ToString() + "  " + "IsConnected:" + IsConnected);
                //player.isConnect = false;//房间中的连接属性

                Dispose();//调用父类里面的方法，会把socket释放
                bool b = AllGames.peerList.Remove(this);
                if (b)
                {
                    Console.WriteLine("从peerList中移除了peer，ID:" + userinfo.id);
                }
                if (gamestate == GameState.login || gamestate == GameState.lobby)
                {

                }
                else
                {
                    if (gamestate == GameState.ready || gamestate == GameState.score)
                    {
                        desk.isJoin = false;
                        player.isReady = false;

                    }
                    else if (gamestate == GameState.gameing)
                    {
                        desk.isJoin = true;
                    }

                    //在房间中判断是不是master，如果是则更换一下master
                    //对masterclientid属性进行设置
                    if (room.masterClientID == player.actorId)
                    {
                        Console.WriteLine("我是masterclient,我掉线了，需要更换masterID");

                        if (room.desk_dong.isJoin || room.desk_nan.isJoin || room.desk_xi.isJoin || room.desk_bei.isJoin)
                        {
                            for (int i = 0; i < room.desklist.Count; i++)
                            {
                                if (room.desklist[i].peer != null && room.desklist[i].isJoin && room.desklist[i].peer != this && room.desklist[i].peer.IsConnected)
                                {
                                    room.masterClientID = room.desklist[i].peer.player.actorId;
                                    break;
                                }
                            }

                            Dictionary<short, object> dict_changeclientid = new Dictionary<short, object>();
                            dict_changeclientid.Add(1, room.masterClientID);
                            for (int i = 0; i < room.desklist.Count; i++)
                            {
                                if (room.desklist[i].isJoin)
                                {
                                    if (room.desklist[i].peer != null && room.desklist[i].peer.IsConnected)
                                    {
                                        room.desklist[i].peer.SendEvent(20, dict_changeclientid);
                                    }
                                }
                            }
                        }
                    }


                    //---发送给其他玩家，玩家掉线的事件---                  
                    Dictionary<short, object> dict_event = new Dictionary<short, object>();
                    dict_event.Add(1, player.actorId);
                    SendToOther(21, dict_event);


                    //判断房间中的所有人是否都掉线，如果都掉线则全部移除玩家，并删除房间               
                    bool isEmpty_dong = false, isEmpty_nan = false, isEmpty_xi = false, isEmpty_bei = false;
                    //dong
                    if (room.desk_dong.peer == null)
                    {
                        isEmpty_dong = true;
                    }

                    if (room.desk_dong.peer != null)
                    {
                        if (room.desk_dong.peer.IsConnected == false)
                        {
                            isEmpty_dong = true;
                        }
                    }
                    if (room.desk_dong.isJoin == false)
                    {
                        isEmpty_dong = true;
                    }

                    //nan
                    if (room.desk_nan.peer == null)
                    {
                        isEmpty_nan = true;
                    }

                    if (room.desk_nan.peer != null)
                    {
                        if (room.desk_nan.peer.IsConnected == false)
                        {
                            isEmpty_nan = true;
                        }
                    }
                    if (room.desk_nan.isJoin == false)
                    {
                        isEmpty_nan = true;
                    }

                    //xi
                    if (room.desk_xi.peer == null)
                    {
                        isEmpty_xi = true;
                    }

                    if (room.desk_xi.peer != null)
                    {
                        if (room.desk_xi.peer.IsConnected == false)
                        {
                            isEmpty_xi = true;
                        }
                    }
                    if (room.desk_xi.isJoin == false)
                    {
                        isEmpty_xi = true;
                    }

                    //bei
                    if (room.desk_bei.peer == null)
                    {
                        isEmpty_bei = true;
                    }

                    if (room.desk_bei.peer != null)
                    {
                        if (room.desk_bei.peer.IsConnected == false)
                        {
                            isEmpty_bei = true;
                        }
                    }
                    if (room.desk_bei.isJoin == false)
                    {
                        isEmpty_bei = true;
                    }

                    if (isEmpty_dong && isEmpty_nan && isEmpty_xi && isEmpty_bei)
                    {
                        try
                        {
                            if (AllGames.dict_rooms.ContainsKey(room.RoomName))
                            {
                                AllGames.dict_rooms.Remove(room.RoomName);
                            }
                            if (AllGames.dict_rooms_tongYongMJ_coin.ContainsKey(room.RoomName))
                            {
                                AllGames.dict_rooms_tongYongMJ_coin.Remove(room.RoomName);
                            }
                            room.Dispose();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("离开房间后移除房间异常：" + ex.Message);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("有客户端离开了");
            }
            
        }

        /// <summary>
        /// 当客户端出现异常时
        /// </summary>
        /// <param name="exception"></param>
        /// <exception cref="NotImplementedException"></exception>
        public override void OnException(Exception exception)
        {
            Console.WriteLine(" OnException");
        }
        /// <summary>
        /// 当客户端发送请求时
        /// </summary>
        /// <param name="opCode"></param>
        /// <param name="dict"></param>
        /// <exception cref="NotImplementedException"></exception>
        public override void OnOperationRequest(short opCode, Dictionary<short, object> dict)
        {
            if (opCode == 1)//通过玩家传来的ID获取数据库信息返还给玩家
            {
                
                string username = Converter<string>(dict[1]);
                string password=Converter<string>(dict[2]);
                bool IsUesrExit=MySQLManager.IsUserExit(username);
                string dataPassword = MySQLManager.UseUserNamefindPassword(username);
                if (IsUesrExit)
                {
                    if (password == dataPassword)
                    {
                        int ID = MySQLManager.UseUserNamefindid(username);
                        int Coin = MySQLManager.UseIDfindCoin(ID);
                        int Diamond = MySQLManager.UseIDfindDiamond(ID);
                        int sex = MySQLManager.UseIDfindsex(ID);
                        bool isLingJiang = MySQLManager.UseIDfindLingJingMessage(ID);
                        string all = "id是" + "username是" + username + "Coin是" + Coin + "Diamond是" + Diamond + "sex是" + sex + "领奖情况是" + isLingJiang;
                        Console.WriteLine(all);
                        userinfo.id = ID;
                        userinfo.username = username;
                        userinfo.coin = Coin;
                        userinfo.diamond = Diamond;
                        userinfo.sex = sex;

                        Dictionary<short, object> dictResponse = new Dictionary<short, object>();
                        dictResponse.Add(1, username);
                        dictResponse.Add(2, Coin);
                        dictResponse.Add(3, Diamond);
                        dictResponse.Add(4, sex);
                        dictResponse.Add(5, isLingJiang);
                        player.username = username;
                        player.coin = Coin;
                        player.sex = sex;
                        SendResponse(opCode, ReturnCode.success, dictResponse);
                        gamestate = GameState.lobby;//让游戏状态变成进入大厅
                        Console.WriteLine("数据库有这个人，登陆吧");
                    }
                    else
                    {
                        SendResponse(17, ReturnCode.success, null);
                    }
                    
                }
                else
                {
                    Console.WriteLine("数据库没有这个人，让客户端注册一个");
                }

            }
            else if (opCode == 2)//玩家创建的房间信息
            {
                room = new Room();
                room.isKechi = (bool)dict[1];
                room.Jushu = (int)(long)dict[2];
                room.AllActorCount++;
                player.actorId = room.AllActorCount;
                Console.WriteLine(room.isKechi + "和" + room.Jushu);

                Random random = new Random();
                int roomname = random.Next(10001, 100000);
                room.RoomName = roomname;
                room.roomInfo.roomName = roomname;
                room.roomInfo.yuePaiJuShu = room.Jushu;
                room.masterClientID = player.actorId;
                AllGames.dict_rooms.Add(roomname, room);

                player.jiFen = 0;
                player.playerPos = PlayerPosition.dong;
                room.desk_dong.isJoin = true;
                room.desk_dong.peer = this;
                AllGames.peerList.Add(this);
                player.IsMasterClientID = true;
                //desk = room.desk_dong;
                Dictionary<short, object> dictResponse = new Dictionary<short, object>();
                dictResponse.Add(1, room.isKechi);
                dictResponse.Add(2, room.Jushu);
                dictResponse.Add(3, room.RoomName);
                dictResponse.Add(4, player);
                SendResponse(opCode, ReturnCode.success, dictResponse);
                gamestate = GameState.ready;
            }
            else if (opCode == 3)//玩家加入房间功能
            {
                string roomname = (string)dict[1];
                int int_room = int.Parse(roomname);
                Console.WriteLine("你想加入的房间号是" + int_room);
                if (AllGames.dict_rooms.ContainsKey(int_room))
                {
                    room = AllGames.dict_rooms[int_room];
                    player.jiFen = 0;
                    if (room.desk_dong.isJoin == false)
                    {
                        player.playerPos = PlayerPosition.dong;
                        room.desk_dong.isJoin = true;
                        room.desk_dong.peer = this;
                        if (AllGames.peerList.Contains(this))
                        {

                        }
                        else
                        {
                            AllGames.peerList.Add(this);
                        }
                        
                        //desk = room.desk_dong;
                        room.AllActorCount++;
                        player.actorId = room.AllActorCount;
                    }//如果这个位置没有加入，那就加入进去
                    else if (room.desk_nan.isJoin == false)
                    {
                        player.playerPos = PlayerPosition.nan;
                        room.desk_nan.isJoin = true;
                        room.desk_nan.peer = this;
                        if (AllGames.peerList.Contains(this))
                        {

                        }
                        else
                        {
                            AllGames.peerList.Add(this);
                        }
                        //desk = room.desk_nan;
                        room.AllActorCount++;
                        player.actorId = room.AllActorCount;
                    }
                    else if (room.desk_xi.isJoin == false)
                    {
                        player.playerPos = PlayerPosition.xi;
                        room.desk_xi.isJoin = true;
                        room.desk_xi.peer = this;
                        if (AllGames.peerList.Contains(this))
                        {

                        }
                        else
                        {
                            AllGames.peerList.Add(this);
                        }
                        //desk = room.desk_xi;
                        room.AllActorCount++;
                        player.actorId = room.AllActorCount;
                    }
                    else if (room.desk_bei.isJoin == false)
                    {
                        player.playerPos = PlayerPosition.bei;
                        room.desk_bei.isJoin = true;
                        room.desk_bei.peer = this;
                        if (AllGames.peerList.Contains(this))
                        {

                        }
                        else
                        {
                            AllGames.peerList.Add(this);
                        }
                        //desk = room.desk_bei;
                        room.AllActorCount++;
                        player.actorId = room.AllActorCount;
                    }
                    Dictionary<short, object> dictResponse = new Dictionary<short, object>();
                    dictResponse.Add(1, room.RoomName);
                    dictResponse.Add(2, room.isKechi);
                    dictResponse.Add(3, room.Jushu);
                    dictResponse.Add(4, player);


                    //如果有人加入了，就把当前加入的这个玩家添加到这个player类里面
                    List<Player> list = new List<Player>();
                    if (room.desk_dong.isJoin)
                    {
                        list.Add(room.desk_dong.peer.player);
                    }
                    if (room.desk_nan.isJoin)
                    {
                        list.Add(room.desk_nan.peer.player);
                    }
                    if (room.desk_xi.isJoin)
                    {
                        list.Add(room.desk_xi.peer.player);
                    }
                    if (room.desk_bei.isJoin)
                    {
                        list.Add(room.desk_bei.peer.player);
                    }
                    dictResponse.Add(5, list);
                    SendResponse(opCode, ReturnCode.success, dictResponse);

                    Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                    dict_ev.Add(6, player);
                    //for (int i = 0; i < room.desklist.Count; i++)
                    //{
                    //}
                    //只要房间内有一个位置不是空的就把所有的其他位置的玩家的信息发送一下
                    if (player.playerPos == PlayerPosition.dong)
                    {
                        if (room.desk_nan.isJoin)
                        {
                            room.desk_nan.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_xi.isJoin)
                        {
                            room.desk_xi.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_bei.isJoin)
                        {
                            room.desk_bei.peer.SendEvent(2, dict_ev);
                        }

                    }
                    else if (player.playerPos == PlayerPosition.nan)
                    {
                        if (room.desk_xi.isJoin)
                        {
                            room.desk_xi.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_bei.isJoin)
                        {
                            room.desk_bei.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_dong.isJoin)
                        {
                            room.desk_dong.peer.SendEvent(2, dict_ev);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.xi)
                    {

                        if (room.desk_bei.isJoin)
                        {
                            room.desk_bei.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_dong.isJoin)
                        {
                            room.desk_dong.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_nan.isJoin)
                        {
                            room.desk_nan.peer.SendEvent(2, dict_ev);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.bei)
                    {

                        if (room.desk_dong.isJoin)
                        {
                            room.desk_dong.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_nan.isJoin)
                        {
                            room.desk_nan.peer.SendEvent(2, dict_ev);
                        }
                        if (room.desk_xi.isJoin)
                        {
                            room.desk_xi.peer.SendEvent(2, dict_ev);
                        }
                    }
                }
                gamestate = GameState.ready;
            }//玩家加入房间功能
            else if (opCode == 4)
            {
                player.isReady = false;
                if (player.playerPos == PlayerPosition.dong)
                {
                    room.desk_dong.isJoin = false;
                    if (room.masterClientID == player.actorId)
                    {
                        if (room.desk_nan.isJoin)
                        {
                            room.masterClientID = room.desk_nan.peer.player.actorId;
                            room.desk_nan.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_xi.isJoin)
                        {
                            room.masterClientID = room.desk_xi.peer.player.actorId;
                            room.desk_xi.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_bei.isJoin)
                        {
                            room.masterClientID = room.desk_bei.peer.player.actorId;
                            room.desk_bei.peer.player.IsMasterClientID = true;
                        }
                    }
                }
                else if (player.playerPos == PlayerPosition.nan)
                {
                    room.desk_nan.isJoin = false;
                    if (room.masterClientID == player.actorId)
                    {
                        if (room.desk_xi.isJoin)
                        {
                            room.masterClientID = room.desk_xi.peer.player.actorId;
                            room.desk_xi.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_bei.isJoin)
                        {
                            room.masterClientID = room.desk_bei.peer.player.actorId;
                            room.desk_bei.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_dong.isJoin)
                        {
                            room.masterClientID = room.desk_dong.peer.player.actorId;
                            room.desk_dong.peer.player.IsMasterClientID = true;
                        }
                    }
                }
                else if (player.playerPos == PlayerPosition.xi)
                {
                    room.desk_xi.isJoin = false;
                    if (room.masterClientID == player.actorId)
                    {
                        if (room.desk_bei.isJoin)
                        {
                            room.masterClientID = room.desk_bei.peer.player.actorId;
                            room.desk_bei.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_dong.isJoin)
                        {
                            room.masterClientID = room.desk_dong.peer.player.actorId;
                            room.desk_dong.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_nan.isJoin)
                        {
                            room.masterClientID = room.desk_nan.peer.player.actorId;
                            room.desk_nan.peer.player.IsMasterClientID = true;
                        }
                    }
                }
                else if (player.playerPos == PlayerPosition.bei)
                {
                    room.desk_bei.isJoin = false;
                    if (room.masterClientID == player.actorId)
                    {
                        if (room.desk_dong.isJoin)
                        {
                            room.masterClientID = room.desk_dong.peer.player.actorId;
                            room.desk_dong.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_nan.isJoin)
                        {
                            room.masterClientID = room.desk_nan.peer.player.actorId;
                            room.desk_nan.peer.player.IsMasterClientID = true;
                        }
                        else if (room.desk_xi.isJoin)
                        {
                            room.masterClientID = room.desk_xi.peer.player.actorId;
                            room.desk_xi.peer.player.IsMasterClientID = true;
                        }
                    }
                }
                SendResponse(opCode, ReturnCode.success, null);
                Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                dict_ev.Add(1, player.actorId);
                SendToOther(3, dict_ev);
                gamestate = GameState.lobby;
            }//玩家离开房间功能
            else if (opCode == 5)
            {
                player.isReady = true;
                SendResponse(opCode, ReturnCode.success, null);
                Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                dict_ev.Add(1, player.actorId);
                SendToOther(4, dict_ev);
                if (room.desk_dong.peer == null || room.desk_nan.peer== null || room.desk_xi.peer== null || room.desk_bei.peer== null) return;
                if (room.desk_dong.peer.player.isReady && room.desk_nan.peer.player.isReady && room.desk_xi.peer.player.isReady && room.desk_bei.peer.player.isReady)
                {
                    //发牌
                    room.InitPai();
                    room.duiZhanJvShu++;
                    room.roomInfo.duiZhanJuShu++;
                    List<int> listdong = new List<int>();
                    List<int> listnan = new List<int>();
                    List<int> listxi = new List<int>();
                    List<int> listbei = new List<int>();
                    for (int i = 0; i < 13; i++)
                    {
                        listdong.Add(room.queue_pai.Dequeue());
                    }
                    for (int i = 0; i < 13; i++)
                    {
                        listnan.Add(room.queue_pai.Dequeue());
                    }
                    for (int i = 0; i < 13; i++)
                    {
                        listxi.Add(room.queue_pai.Dequeue());
                    }
                    for (int i = 0; i < 13; i++)
                    {
                        listbei.Add(room.queue_pai.Dequeue());
                    }
                    //listdong.Add(3);
                    //listdong.Add(3);
                    //listdong.Add(6);
                    //listdong.Add(7);
                    //listdong.Add(7);
                    //listdong.Add(8);
                    //listdong.Add(42);
                    //listnan.Add(3);
                    //listnan.Add(5);
                    //listnan.Add(6);
                    //listnan.Add(6);
                    //listxi.Add(3);
                    //listxi.Add(43);
                    //listbei.Add(33);
                    //listbei.Add(71);
                    room.desk_dong.shoupai = listdong;
                    room.desk_nan.shoupai = listnan;
                    room.desk_xi.shoupai = listxi;
                    room.desk_bei.shoupai = listbei;
                    int mopai = room.queue_pai.Dequeue();
                    room.yvPaiJvShu = room.queue_pai.Count;
                    int moPaiPlayerID = 0;

                    if (room.masterClientID == room.desk_dong.peer.player.actorId)
                    {
                        room.desk_dong.mopai = mopai;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = 0;
                        moPaiPlayerID = room.desk_dong.peer.player.actorId;
                    }
                    else if (room.masterClientID == room.desk_nan.peer.player.actorId)
                    {
                        room.desk_nan.mopai = mopai;
                        room.desk_dong.mopai = 0;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = 0;
                        moPaiPlayerID = room.desk_nan.peer.player.actorId;
                    }
                    else if (room.masterClientID == room.desk_xi.peer.player.actorId)
                    {
                        room.desk_xi.mopai = mopai;
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = 0;
                        room.desk_bei.mopai = 0;
                        moPaiPlayerID = room.desk_xi.peer.player.actorId;
                    }
                    else if (room.masterClientID == room.desk_bei.peer.player.actorId)
                    {
                        room.desk_bei.mopai = mopai;
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = 0;
                        moPaiPlayerID = room.desk_bei.peer.player.actorId;
                    }
                    Dictionary<short, object> dict_ev1 = new Dictionary<short, object>();
                    dict_ev1[1] = listdong;
                    dict_ev1[2] = room.desk_dong.mopai;
                    dict_ev1[3] = room.duiZhanJvShu;
                    dict_ev1[4] = room.Jushu;
                    dict_ev1[5] = room.yvPaiJvShu;
                    dict_ev1[6] = moPaiPlayerID;
                    if (room.desk_dong.peer != null && room.desk_dong.peer.IsConnected)
                    {
                        room.desk_dong.peer.SendEvent(5, dict_ev1);
                    }

                    Dictionary<short, object> dict_ev2 = new Dictionary<short, object>();
                    dict_ev2[1] = listnan;
                    dict_ev2[2] = room.desk_nan.mopai;
                    dict_ev2[3] = room.duiZhanJvShu;
                    dict_ev2[4] = room.Jushu;
                    dict_ev2[5] = room.yvPaiJvShu;
                    dict_ev2[6] = moPaiPlayerID;
                    if (room.desk_nan.peer != null && room.desk_nan.peer.IsConnected)
                    {
                        room.desk_nan.peer.SendEvent(5, dict_ev2);
                    }

                    Dictionary<short, object> dict_ev3 = new Dictionary<short, object>();
                    dict_ev3[1] = listxi;
                    dict_ev3[2] = room.desk_xi.mopai;
                    dict_ev3[3] = room.duiZhanJvShu;
                    dict_ev3[4] = room.Jushu;
                    dict_ev3[5] = room.yvPaiJvShu;
                    dict_ev3[6] = moPaiPlayerID;
                    if (room.desk_xi.peer != null && room.desk_xi.peer.IsConnected)
                    {
                        room.desk_xi.peer.SendEvent(5, dict_ev3);
                    }

                    Dictionary<short, object> dict_ev4 = new Dictionary<short, object>();
                    dict_ev4[1] = listbei;
                    dict_ev4[2] = room.desk_bei.mopai;
                    dict_ev4[3] = room.duiZhanJvShu;
                    dict_ev4[4] = room.Jushu;
                    dict_ev4[5] = room.yvPaiJvShu;
                    dict_ev4[6] = moPaiPlayerID;
                    if (room.desk_bei.peer != null && room.desk_bei.peer.IsConnected)
                    {
                        room.desk_bei.peer.SendEvent(5, dict_ev4);

                    }
                    if (room.roomInfo.isYuePai)
                    {
                        room.needChuPaiID = room.desk_dong.peer.player.actorId;
                    }
                    else//设置成庄家的ID
                    {
                        room.needChuPaiID = room.masterClientID;
                    }
                    room.timer_NeedChuPaiJiShi.Start();
                    room.desk_dong.peer.gamestate = GameState.gameing;
                    room.desk_nan.peer.gamestate = GameState.gameing;
                    room.desk_xi.peer.gamestate = GameState.gameing;
                    room.desk_bei.peer.gamestate = GameState.gameing;
                    //SendEventToAll(19, null);
                }

            }//当玩家都到了以后发牌
            else if (opCode == 6) //获取刚刚打牌的玩家，和他打出来的牌，同步给其他玩家
            {
                int lostPaiShuZi = (int)(long)dict[1];  //打出来的牌数字
                bool isMoPai = (bool)dict[2];         //是否是摸牌
                bool isGangHouChuPai = (bool)dict[3];  //是否是杠后出牌

                room.timer_NeedChuPaiJiShi.Stop();
                if (isMoPai)//如果打的是摸得牌，就把这张牌添加到对应玩家的出牌堆里去，并且把这个玩家的摸牌数变成0
                {
                    if (player.playerPos == PlayerPosition.dong)
                    {
                        room.desk_dong.throwpai.Add(lostPaiShuZi);
                        room.desk_dong.mopai = 0;
                        while (room.desk_dong.shoupai.Contains(0))
                        {
                            room.desk_dong.shoupai.Remove(0);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.nan)
                    {
                        room.desk_nan.throwpai.Add(lostPaiShuZi);
                        room.desk_nan.mopai = 0;
                        while (room.desk_nan.shoupai.Contains(0))
                        {
                            room.desk_nan.shoupai.Remove(0);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.xi)
                    {
                        room.desk_xi.throwpai.Add(lostPaiShuZi);
                        room.desk_xi.mopai = 0;
                        while (room.desk_xi.shoupai.Contains(0))
                        {
                            room.desk_xi.shoupai.Remove(0);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.bei)
                    {
                        room.desk_bei.throwpai.Add(lostPaiShuZi);
                        room.desk_bei.mopai = 0;
                        while (room.desk_bei.shoupai.Contains(0))
                        {
                            room.desk_bei.shoupai.Remove(0);
                        }
                    }
                }//判断打出来的牌的类型，把打出来的牌与玩家的手牌进行操作，同时放入弃牌堆
                else //如果打的不是摸的牌，得把这个牌从手牌里面删除出去
                {
                    if (player.playerPos == PlayerPosition.dong)
                    {
                        room.desk_dong.throwpai.Add(lostPaiShuZi);
                        room.desk_dong.shoupai.Add(room.desk_dong.mopai);
                        room.desk_dong.shoupai.Remove(lostPaiShuZi);
                        room.desk_dong.mopai = 0;
                        while (room.desk_dong.shoupai.Contains(0))
                        {
                            room.desk_dong.shoupai.Remove(0);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.nan)
                    {
                        room.desk_nan.throwpai.Add(lostPaiShuZi);
                        room.desk_nan.shoupai.Add(room.desk_nan.mopai);
                        room.desk_nan.shoupai.Remove(lostPaiShuZi);
                        room.desk_nan.mopai = 0;
                        while (room.desk_nan.shoupai.Contains(0))
                        {
                            room.desk_nan.shoupai.Remove(0);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.xi)
                    {
                        room.desk_xi.throwpai.Add(lostPaiShuZi);
                        room.desk_xi.shoupai.Add(room.desk_xi.mopai);
                        room.desk_xi.shoupai.Remove(lostPaiShuZi);
                        room.desk_xi.mopai = 0;
                        while (room.desk_xi.shoupai.Contains(0))
                        {
                            room.desk_xi.shoupai.Remove(0);
                        }
                    }
                    else if (player.playerPos == PlayerPosition.bei)
                    {
                        room.desk_bei.throwpai.Add(lostPaiShuZi);
                        room.desk_bei.shoupai.Add(room.desk_bei.mopai);
                        room.desk_bei.shoupai.Remove(lostPaiShuZi);
                        room.desk_bei.mopai = 0;
                        while (room.desk_bei.shoupai.Contains(0))
                        {
                            room.desk_bei.shoupai.Remove(0);
                        }
                    }
                }
                room.needChuPaiID = 0;


                if (player.playerPos == PlayerPosition.dong)
                {
                    Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_nan = jianCe.JiancePenggangLeixing(room.desk_nan, lostPaiShuZi);
                    List<int> listchi_nan = jianCe.JianCeXiajiachi(room.desk_nan, lostPaiShuZi);
                    Dictionary<short, object> paileiXing_nan = new Dictionary<short, object>();
                    paileiXing_nan.Add(1, hplx_nan);
                    paileiXing_nan.Add(2, pglx_nan);
                    paileiXing_nan.Add(3, listchi_nan);
                    paileiXing_nan.Add(4, lostPaiShuZi);
                    room.desk_nan.peer.SendEvent(7, paileiXing_nan);

                    Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_xi = jianCe.JiancePenggangLeixing(room.desk_xi, lostPaiShuZi);
                    List<int> listchi_xi = null;
                    Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                    paileiXing_xi.Add(1, hplx_xi);
                    paileiXing_xi.Add(2, pglx_xi);
                    paileiXing_xi.Add(3, listchi_xi);
                    paileiXing_xi.Add(4, lostPaiShuZi);
                    room.desk_xi.peer.SendEvent(7, paileiXing_xi);

                    Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_bei = jianCe.JiancePenggangLeixing(room.desk_bei, lostPaiShuZi);
                    List<int> listchi_bei = null;
                    Dictionary<short, object> paileiXing_bei = new Dictionary<short, object>();
                    paileiXing_bei.Add(1, hplx_bei);
                    paileiXing_bei.Add(2, pglx_bei);
                    paileiXing_bei.Add(3, listchi_bei);
                    paileiXing_bei.Add(4, lostPaiShuZi);
                    room.desk_bei.peer.SendEvent(7, paileiXing_bei);
                }  //判断刚刚出牌的人是谁，让除他之外的所有人看看自己能否胡牌，碰牌，杠牌
                else if (player.playerPos == PlayerPosition.nan)
                {
                    Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_xi = jianCe.JiancePenggangLeixing(room.desk_xi, lostPaiShuZi);
                    List<int> listchi_xi = jianCe.JianCeXiajiachi(room.desk_xi, lostPaiShuZi);
                    Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                    paileiXing_xi.Add(1, hplx_xi);
                    paileiXing_xi.Add(2, pglx_xi);
                    paileiXing_xi.Add(3, listchi_xi);
                    paileiXing_xi.Add(4, lostPaiShuZi);
                    room.desk_xi.peer.SendEvent(7, paileiXing_xi);

                    Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_bei = jianCe.JiancePenggangLeixing(room.desk_bei, lostPaiShuZi);
                    List<int> listchi_bei = null;
                    Dictionary<short, object> paileiXing_bei = new Dictionary<short, object>();
                    paileiXing_bei.Add(1, hplx_bei);
                    paileiXing_bei.Add(2, pglx_bei);
                    paileiXing_bei.Add(3, listchi_bei);
                    paileiXing_bei.Add(4, lostPaiShuZi);
                    room.desk_bei.peer.SendEvent(7, paileiXing_bei);

                    Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_dong = jianCe.JiancePenggangLeixing(room.desk_dong, lostPaiShuZi);
                    List<int> listchi_dong = null;
                    Dictionary<short, object> paileiXing_dong = new Dictionary<short, object>();
                    paileiXing_dong.Add(1, hplx_dong);
                    paileiXing_dong.Add(2, pglx_dong);
                    paileiXing_dong.Add(3, listchi_dong);
                    paileiXing_dong.Add(4, lostPaiShuZi);
                    room.desk_dong.peer.SendEvent(7, paileiXing_dong);
                }
                else if (player.playerPos == PlayerPosition.xi)
                {
                    Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_bei = jianCe.JiancePenggangLeixing(room.desk_bei, lostPaiShuZi);
                    List<int> listchi_bei = jianCe.JianCeXiajiachi(room.desk_bei, lostPaiShuZi);
                    Dictionary<short, object> paileiXing_bei = new Dictionary<short, object>();
                    paileiXing_bei.Add(1, hplx_bei);
                    paileiXing_bei.Add(2, pglx_bei);
                    paileiXing_bei.Add(3, listchi_bei);
                    paileiXing_bei.Add(4, lostPaiShuZi);
                    room.desk_bei.peer.SendEvent(7, paileiXing_bei);

                    Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_dong = jianCe.JiancePenggangLeixing(room.desk_dong, lostPaiShuZi);
                    List<int> listchi_dong = null;
                    Dictionary<short, object> paileiXing_dong = new Dictionary<short, object>();
                    paileiXing_dong.Add(1, hplx_dong);
                    paileiXing_dong.Add(2, pglx_dong);
                    paileiXing_dong.Add(3, listchi_dong);
                    paileiXing_dong.Add(4, lostPaiShuZi);
                    room.desk_dong.peer.SendEvent(7, paileiXing_dong);

                    Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_nan = jianCe.JiancePenggangLeixing(room.desk_nan, lostPaiShuZi);
                    List<int> listchi_nan = null;
                    Dictionary<short, object> paileiXing_nan = new Dictionary<short, object>();
                    paileiXing_nan.Add(1, hplx_nan);
                    paileiXing_nan.Add(2, pglx_nan);
                    paileiXing_nan.Add(3, listchi_nan);
                    paileiXing_nan.Add(4, lostPaiShuZi);
                    room.desk_nan.peer.SendEvent(7, paileiXing_nan);
                }
                else if (player.playerPos == PlayerPosition.bei)
                {
                    Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_dong = jianCe.JiancePenggangLeixing(room.desk_dong, lostPaiShuZi);
                    List<int> listchi_dong = jianCe.JianCeXiajiachi(room.desk_dong, lostPaiShuZi);
                    Dictionary<short, object> paileiXing_dong = new Dictionary<short, object>();
                    paileiXing_dong.Add(1, hplx_dong);
                    paileiXing_dong.Add(2, pglx_dong);
                    paileiXing_dong.Add(3, listchi_dong);
                    paileiXing_dong.Add(4, lostPaiShuZi);
                    room.desk_dong.peer.SendEvent(7, paileiXing_dong);

                    Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_nan = jianCe.JiancePenggangLeixing(room.desk_nan, lostPaiShuZi);
                    List<int> listchi_nan = null;
                    Dictionary<short, object> paileiXing_nan = new Dictionary<short, object>();
                    paileiXing_nan.Add(1, hplx_nan);
                    paileiXing_nan.Add(2, pglx_nan);
                    paileiXing_nan.Add(3, listchi_nan);
                    paileiXing_nan.Add(4, lostPaiShuZi);
                    room.desk_nan.peer.SendEvent(7, paileiXing_nan);

                    Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, lostPaiShuZi, isGangHouChuPai, false);
                    PengGangLeixing pglx_xi = jianCe.JiancePenggangLeixing(room.desk_xi, lostPaiShuZi);
                    List<int> listchi_xi = null;
                    Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                    paileiXing_xi.Add(1, hplx_xi);
                    paileiXing_xi.Add(2, pglx_xi);
                    paileiXing_xi.Add(3, listchi_xi);
                    paileiXing_xi.Add(4, lostPaiShuZi);
                    room.desk_xi.peer.SendEvent(7, paileiXing_xi);
                }

                room.list_huReturn.Clear();
                room.list_pgReturn.Clear();
                room.list_chiReturn.Clear();

                SendEventToAll(19, null);
                //room.timer_ChuPaiReturnJiShi.Start();

                room.isExcutedChuPaiDataReturn = false;
                room.isExcutedChuPaiDataReturn = false;
                room.chupaishuzi = lostPaiShuZi;
                room.chuPaiID = player.actorId;
                room.desk_dong.isChuPaiReturn = false;
                room.desk_nan.isChuPaiReturn = false;
                room.desk_xi.isChuPaiReturn = false;
                room.desk_bei.isChuPaiReturn = false;
                room.isChuPaiReturn = true;
                Dictionary<short, object> PaiMessage = new Dictionary<short, object>();
                PaiMessage.Add(1, player.actorId);
                PaiMessage.Add(2, lostPaiShuZi);
                PaiMessage.Add(3, isMoPai);
                SendToOther(6, PaiMessage);
                List<int> dong = room.desk_dong.shoupai;
                dong.Sort();
                List<int> nan = room.desk_nan.shoupai;
                nan.Sort();
                List<int> xi = room.desk_xi.shoupai;
                xi.Sort();
                room.timer_ChuPaiReturnJiShi.Start();
                List<int> bei = room.desk_bei.shoupai;
                bei.Sort();
                Console.WriteLine("玩家东的手牌有");
                for (int i = 0; i < dong.Count; i++)
                {
                    Console.Write(dong[i]+" ");
                }
                Console.WriteLine("玩家南的手牌有");
                for (int i = 0; i < nan.Count; i++)
                {
                    Console.Write(nan[i]+" ");
                }
                Console.WriteLine("玩家西的手牌有");
                for (int i = 0; i < xi.Count; i++)
                {
                    Console.Write(xi[i]+" ");
                }
                Console.WriteLine("玩家北的手牌有");
                for (int i = 0; i < bei.Count; i++)
                {
                    Console.Write(bei[i]+" ");
                }

            }//获取刚刚打牌的玩家，和他打出来的牌，同步给其他玩家
            else if (opCode == 7)
            {
                List<int> ChiThrowPai = new List<int>();
                List<int> PengThrowPai = new List<int>();
                List<int> GangThrowPai = new List<int>();
                Hupaileixing hplx = Hupaileixing.buhu;
                PengGangLeixing pglx = PengGangLeixing.BupengBuGang;
                OtherChuPaiResponse otherChuPaiResponse = Converter<OtherChuPaiResponse>(dict[1]);
                if (otherChuPaiResponse == OtherChuPaiResponse.chipai)
                {
                    ChiThrowPai = Converter<List<int>>(dict[2]);
                    ChiThrowPai.Sort();
                }
                if (otherChuPaiResponse == OtherChuPaiResponse.pengpai)
                {
                    PengThrowPai = Converter<List<int>>(dict[3]);
                    pglx = PengGangLeixing.Peng;
                }
                if (otherChuPaiResponse == OtherChuPaiResponse.gangpai)
                {
                    GangThrowPai = Converter<List<int>>(dict[4]);
                    pglx = PengGangLeixing.Gang;
                }
                if (otherChuPaiResponse == OtherChuPaiResponse.hupai)
                {
                    hplx = Converter<Hupaileixing>(dict[2]);
                }
                #region 我的理解，当玩家进行碰杠后对牌的处理
                //if(otherChuPaiResponse== OtherChuPaiResponse.chipai)
                //{
                //    Dictionary<short, object> Chidict = new Dictionary<short, object>();
                //    Chidict.Add(1, otherChuPaiResponse);
                //    Chidict.Add(2, pengGangThrowPai);
                //    Chidict.Add(3, player.playerPos);
                //    SendToOther(8, Chidict);
                //    if (player.playerPos == PlayerPosition.dong)
                //    {
                //        for (int i = 0; i < pengGangThrowPai.Count; i++)
                //        {
                //            room.desk_dong.throwpai.Add(pengGangThrowPai[i]);
                //            room.desk_dong.shoupai.Remove(pengGangThrowPai[i]);
                //        }
                //        Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, -1, false, false);
                //        PengGangLeixing pglx_dong = jianCe.JiancePenggangLeixing(room.desk_dong, -1);
                //        List<int> listchi_dong = null;
                //        Dictionary<short, object> paileiXing_dong = new Dictionary<short, object>();
                //        paileiXing_dong.Add(1, hplx_dong);
                //        paileiXing_dong.Add(2, pglx_dong);
                //        paileiXing_dong.Add(3, listchi_dong);
                //        paileiXing_dong.Add(4, -1);
                //        room.desk_bei.peer.SendEvent(7, paileiXing_dong);
                //    }
                //    else if (player.playerPos == PlayerPosition.nan)
                //    {
                //        for (int i = 0; i < pengGangThrowPai.Count; i++)
                //        {
                //            room.desk_nan.throwpai.Add(pengGangThrowPai[i]);
                //            room.desk_nan.shoupai.Remove(pengGangThrowPai[i]);
                //        }
                //        Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, -1, false, false);
                //        PengGangLeixing pglx_nan = jianCe.JiancePenggangLeixing(room.desk_nan, -1);
                //        List<int> listchi_nan = null;
                //        Dictionary<short, object> paileiXing_nan = new Dictionary<short, object>();
                //        paileiXing_nan.Add(1, hplx_nan);
                //        paileiXing_nan.Add(2, pglx_nan);
                //        paileiXing_nan.Add(3, listchi_nan);
                //        paileiXing_nan.Add(4, -1);
                //    }
                //    else if (player.playerPos == PlayerPosition.xi)
                //    {
                //        for (int i = 0; i < pengGangThrowPai.Count; i++)
                //        {
                //            room.desk_xi.throwpai.Add(pengGangThrowPai[i]);
                //            room.desk_xi.shoupai.Remove(pengGangThrowPai[i]);
                //        }
                //        Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, -1, false, false);
                //        PengGangLeixing pglx_xi = jianCe.JiancePenggangLeixing(room.desk_xi, -1);
                //        List<int> listchi_xi = null;
                //        Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                //        paileiXing_xi.Add(1, hplx_xi);
                //        paileiXing_xi.Add(2, pglx_xi);
                //        paileiXing_xi.Add(3, listchi_xi);
                //        paileiXing_xi.Add(4, -1);
                //        room.desk_xi.peer.SendEvent(7, paileiXing_xi);
                //    }
                //    else if (player.playerPos == PlayerPosition.bei)
                //    {
                //        for (int i = 0; i < pengGangThrowPai.Count; i++)
                //        {
                //            room.desk_bei.throwpai.Add(pengGangThrowPai[i]);
                //            room.desk_bei.shoupai.Remove(pengGangThrowPai[i]);
                //        }
                //        Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, -1, false, false);
                //        PengGangLeixing pglx_bei = jianCe.JiancePenggangLeixing(room.desk_bei, -1);
                //        List<int> listchi_bei = null;
                //        Dictionary<short, object> paileiXing_bei = new Dictionary<short, object>();
                //        paileiXing_bei.Add(1, hplx_bei);
                //        paileiXing_bei.Add(2, pglx_bei);
                //        paileiXing_bei.Add(3, listchi_bei);
                //        paileiXing_bei.Add(4, -1);
                //        room.desk_bei.peer.SendEvent(7, paileiXing_bei);
                //    }
                //}
                //if (otherChuPaiResponse == OtherChuPaiResponse.pengpai)
                //{

                //}
                #endregion




                //把胡牌的、杠牌的、碰牌的、吃牌的添加进dict                          
                if (hplx != Hupaileixing.buhu)
                {
                    HuReturnData hureturn = new HuReturnData();
                    hureturn.hupaiActorID = player.actorId;
                    hureturn.hplx = hplx;
                    room.list_huReturn.Add(hureturn);
                }

                if (pglx != PengGangLeixing.BupengBuGang)
                {
                    PengGangReturnData pgreturn = new PengGangReturnData() { pengGangActorID = player.actorId, pglx = pglx };
                    room.list_pgReturn.Add(pgreturn);
                }

                if (ChiThrowPai.Count > 0)
                {
                    ChiReturnData chireturn = new ChiReturnData() { chiPaiActorID = player.actorId, listchi = ChiThrowPai };
                    room.list_chiReturn.Add(chireturn);
                }

                //当玩家根据出的牌数字判断完自己该吃还是碰什么的，让他的这个属性变成true
                if (player.playerPos == PlayerPosition.dong)
                {
                    room.desk_dong.isChuPaiReturn = true;
                }
                else if (player.playerPos == PlayerPosition.nan)
                {
                    room.desk_nan.isChuPaiReturn = true;
                }
                else if (player.playerPos == PlayerPosition.xi)
                {
                    room.desk_xi.isChuPaiReturn = true;
                }
                else if (player.playerPos == PlayerPosition.bei)
                {
                    room.desk_bei.isChuPaiReturn = true;
                }
                #region 当三家完成对打出牌的处理后，让出牌的玩家也完成牌的判断才能进行下去
                if (room.desk_dong.isChuPaiReturn && room.desk_nan.isChuPaiReturn && room.desk_xi.isChuPaiReturn)
                {
                    room.desk_bei.isChuPaiReturn = true;
                }
                else if (room.desk_nan.isChuPaiReturn && room.desk_xi.isChuPaiReturn && room.desk_bei.isChuPaiReturn)
                {
                    room.desk_dong.isChuPaiReturn = true;
                }
                else if (room.desk_dong.isChuPaiReturn && room.desk_bei.isChuPaiReturn && room.desk_xi.isChuPaiReturn)
                {
                    room.desk_nan.isChuPaiReturn = true;
                }
                else if (room.desk_dong.isChuPaiReturn && room.desk_nan.isChuPaiReturn && room.desk_bei.isChuPaiReturn)
                {
                    room.desk_xi.isChuPaiReturn = true;
                }
                #endregion


                if ((room.desk_dong.isChuPaiReturn || room.desk_dong.peer.IsConnected == false)
                    && (room.desk_nan.isChuPaiReturn || room.desk_nan.peer.IsConnected == false)
                    && (room.desk_xi.isChuPaiReturn || room.desk_xi.peer.IsConnected == false)
                    && (room.desk_bei.isChuPaiReturn || room.desk_bei.peer.IsConnected == false))
                {
                    room.ChuPaiDataReturn();
                }

                Console.WriteLine("玩家" + player.username + "进行了操作，他的选择是" + otherChuPaiResponse);
            }//对刚刚打出的牌进行判断检测
            else if (opCode == 8)  //摸牌
            {
                if (room != null)
                {
                    int mopai = 0;
                    if (room.queue_pai.Count > 0)
                    {
                        mopai = room.queue_pai.Dequeue();
                    }
                    else//当牌没有了时，说明黄牌了，需要发送一个事件给所有人，告诉他们黄牌，并结束
                    {
                        room.OnHuangPai();

                        return;
                    }
                    if (player.playerPos == PlayerPosition.dong)
                    {
                        room.desk_dong.mopai = mopai;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = 0;
                    }
                    else if (player.playerPos == PlayerPosition.nan)
                    {
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = mopai;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = 0;
                    }
                    else if (player.playerPos == PlayerPosition.xi)
                    {
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = mopai;
                        room.desk_bei.mopai = 0;
                    }
                    else if (player.playerPos == PlayerPosition.bei)
                    {
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = mopai;
                    }
                    if (mopai != 0)
                    {
                        Dictionary<short, object> dict_response = new Dictionary<short, object>();
                        dict_response.Add(1, mopai);
                        dict_response.Add(2, room.queue_pai.Count);
                        Console.WriteLine("牌堆里面还剩" + room.queue_pai.Count);
                        SendResponse(6, ReturnCode.success, dict_response);
                        room.isganghouchupai = false;
                        room.needChuPaiID = player.actorId;
                        room.timer_NeedChuPaiJiShi.Start();
                        room.desk_dong.isChuPaiReturn = false;
                        room.desk_nan.isChuPaiReturn = false;
                        room.desk_xi.isChuPaiReturn = false;
                        room.desk_bei.isChuPaiReturn = false;

                        SendEventToAll(19, null); //开启计时功能

                        Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                        dict_ev.Add(1, room.queue_pai.Count);
                        dict_ev.Add(2, player.actorId);
                        SendToOther(11, dict_ev);
                    }
                    else
                    {
                        Dictionary<short, object> dict_response = new Dictionary<short, object>();
                        dict_response.Add(1, "获取摸牌失败");

                    }
                }

            }
            else if (opCode == 9) //杠后摸牌
            {
                if (room != null)
                {
                    int mopai = 0;
                    if (room.queue_pai.Count > 0)
                    {
                        mopai = room.queue_pai.Dequeue();
                    }
                    else
                    {
                        room.OnHuangPai();
                        return;
                    }
                    if (player.playerPos == PlayerPosition.dong)
                    {
                        room.desk_dong.mopai = mopai;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = 0;
                    }
                    else if (player.playerPos == PlayerPosition.nan)
                    {
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = mopai;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = 0;
                    }
                    else if (player.playerPos == PlayerPosition.xi)
                    {
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = mopai;
                        room.desk_bei.mopai = 0;
                    }
                    else if (player.playerPos == PlayerPosition.bei)
                    {
                        room.desk_dong.mopai = 0;
                        room.desk_nan.mopai = 0;
                        room.desk_xi.mopai = 0;
                        room.desk_bei.mopai = mopai;
                    }
                    if (mopai != 0)
                    {
                        Dictionary<short, object> dict_response = new Dictionary<short, object>();
                        dict_response.Add(1, mopai);
                        dict_response.Add(2, room.queue_pai.Count);
                        Console.WriteLine("牌堆里面还剩" + room.queue_pai.Count);
                        SendResponse(6, ReturnCode.success, dict_response);
                        room.isganghouchupai = true;
                        room.needChuPaiID = player.actorId;
                        room.timer_NeedChuPaiJiShi.Start();
                        room.desk_dong.isChuPaiReturn = false;
                        room.desk_nan.isChuPaiReturn = false;
                        room.desk_xi.isChuPaiReturn = false;
                        room.desk_bei.isChuPaiReturn = false;

                        SendEventToAll(19, null); //开启计时功能

                        Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                        dict_ev.Add(1, room.queue_pai.Count);
                        dict_ev.Add(2, player.actorId);
                        SendToOther(11, dict_ev);
                    }
                    else
                    {
                        Dictionary<short, object> dict_response = new Dictionary<short, object>();
                        dict_response.Add(1, "获取摸牌失败");

                    }
                }
            }
            else if (opCode == 10) //处理自摸
            {
                ZiMoLeixing clientzimoleixing = (ZiMoLeixing)(long)dict[1];
                Console.WriteLine("clientzimoleixing:" + clientzimoleixing);

                ZiMoLeixing zmlx = ZiMoLeixing.buzimo;
                int zimoShuzi = 0;
                if (player.playerPos == PlayerPosition.dong)
                {
                    zmlx = jianCe.JianceZimoLeixing(room.desk_dong.shoupai, room.desk_dong.cpg, room.desk_dong.mopai);
                    Console.WriteLine("zmlx:" + zmlx);
                    zimoShuzi = room.desk_dong.mopai;
                }
                else if (player.playerPos == PlayerPosition.nan)
                {
                    zmlx = jianCe.JianceZimoLeixing(room.desk_nan.shoupai, room.desk_nan.cpg, room.desk_nan.mopai);
                    Console.WriteLine("zmlx:" + zmlx);
                    zimoShuzi = room.desk_nan.mopai;
                }
                else if (player.playerPos == PlayerPosition.xi)
                {
                    zmlx = jianCe.JianceZimoLeixing(room.desk_xi.shoupai, room.desk_xi.cpg, room.desk_xi.mopai);
                    Console.WriteLine("zmlx:" + zmlx);
                    zimoShuzi = room.desk_xi.mopai;
                }
                else if (player.playerPos == PlayerPosition.bei)
                {
                    zmlx = jianCe.JianceZimoLeixing(room.desk_bei.shoupai, room.desk_bei.cpg, room.desk_bei.mopai);
                    Console.WriteLine("zmlx:" + zmlx);
                    zimoShuzi = room.desk_bei.mopai;
                }

                if (zmlx == clientzimoleixing)
                {
                    Dictionary<short, object> dict_zimoreturn = new Dictionary<short, object>();
                    dict_zimoreturn.Add(1, zmlx);
                    dict_zimoreturn.Add(2, player.actorId);
                    dict_zimoreturn.Add(3, zimoShuzi);

                    dict_zimoreturn.Add(4, room.desk_dong.shoupai);
                    dict_zimoreturn.Add(5, room.desk_nan.shoupai);
                    dict_zimoreturn.Add(6, room.desk_xi.shoupai);
                    dict_zimoreturn.Add(7, room.desk_bei.shoupai);
                    room.timer_NeedChuPaiJiShi.Stop();

                    //计算一下自摸分数，更新数据库上的分数，再返回给客户端：
                    //开始结算分数
                    JieSuan jiesuan = new JieSuan();

                    if (room.roomInfo.isYuePai)
                    {
                        int winfenshu = jiesuan.GetZiMoScore(room.roomInfo.roomType, zmlx, 1);

                        //先存储
                        //1.先更新赢玩家的积分                              
                        player.jiFen += winfenshu * 3;

                        //2.再更新输玩家，或放炮玩家的分数
                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            if (room.desklist[i].peer != this)
                            {
                                room.desklist[i].peer.player.jiFen -= winfenshu;
                            }
                        }

                        Console.WriteLine("东积分：" + room.desk_dong.peer.player.jiFen + "南积分：" + room.desk_nan.peer.player.jiFen + "西积分：" + room.desk_xi.peer.player.jiFen + "北积分：:" + room.desk_bei.peer.player.jiFen);

                        //保存每个桌子上的积分
                        room.desk_dong.jiFen = room.desk_dong.peer.player.jiFen;
                        room.desk_nan.jiFen = room.desk_nan.peer.player.jiFen;
                        room.desk_xi.jiFen = room.desk_xi.peer.player.jiFen;
                        room.desk_bei.jiFen = room.desk_bei.peer.player.jiFen;

                        int jiFen_dong = room.desk_dong.peer.player.jiFen;
                        int jiFen_nan = room.desk_nan.peer.player.jiFen;
                        int jiFen_xi = room.desk_xi.peer.player.jiFen;
                        int jiFen_bei = room.desk_bei.peer.player.jiFen;

                        dict_zimoreturn.Add(8, jiFen_dong);
                        dict_zimoreturn.Add(9, jiFen_nan);
                        dict_zimoreturn.Add(10, jiFen_xi);
                        dict_zimoreturn.Add(11, jiFen_bei);
                    }
                    else
                    {
                        Console.WriteLine("自摸时房间中的底分是：" + room.diFen);
                        int winfenshu = jiesuan.GetZiMoScore(room.roomInfo.roomType, zmlx, room.diFen);

                        //先存储
                        //1.先更新赢玩家的分数
                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            if (room.desklist[i].peer == this)
                            {
                                MySQLManager.UpdateCoin(winfenshu * 3, room.desklist[i].peer.userinfo.id);
                            }
                        }

                        //2.再更新输玩家，或放炮玩家的分数
                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            if (room.desklist[i].peer != this)
                            {
                                MySQLManager.UpdateCoin(-winfenshu, room.desklist[i].peer.userinfo.id);
                            }
                        }

                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            MySQLManager.UpdatejinriCoinJushu(1, room.desklist[i].peer.userinfo.id);
                            MySQLManager.UpdatejinriZongJushu(1, room.desklist[i].peer.userinfo.id);
                        }
                        //再查询
                        int coin_dong = MySQLManager.UseIDfindDiamond(room.desk_dong.peer.userinfo.id);
                        int coin_nan = MySQLManager.UseIDfindDiamond(room.desk_nan.peer.userinfo.id);
                        int coin_xi = MySQLManager.UseIDfindDiamond(room.desk_xi.peer.userinfo.id);
                        int coin_bei = MySQLManager.UseIDfindDiamond(room.desk_bei.peer.userinfo.id);
                        Console.WriteLine("coin_dong" + coin_dong + "coin_nan" + coin_nan + "coin_xi" + coin_xi + "coin_bei:" + coin_bei);

                        dict_zimoreturn.Add(12, coin_dong);
                        dict_zimoreturn.Add(13, coin_nan);
                        dict_zimoreturn.Add(14, coin_xi);
                        dict_zimoreturn.Add(15, coin_bei);
                    }


                    //胡、自摸、上花、抢杠后更新一下房间信息，做进一步判断，如果约牌局数到了就显示积分，结束约牌。
                    dict_zimoreturn.Add(16, room.roomInfo);


                    for (int i = 0; i < room.desklist.Count; i++)
                    {
                        //room.deskList[i].peer.gamestate = GameState.score;                                
                    }
                    SendEventToAll(14, dict_zimoreturn);

                    room.OnGameOver();

                    gamestate = GameState.score;
                }
            }
            else if (opCode == 11) //杠上开花判断
            {
                ShangHuaLeiXing clientShangHuaLeiXing = (ShangHuaLeiXing)(long)dict[1];
                ShangHuaLeiXing shlx = ShangHuaLeiXing.bushanghua;
                room.timer_NeedChuPaiJiShi.Stop();
                int moPaiShuZi = 0;
                if (player.playerPos == PlayerPosition.dong)
                {
                    shlx = jianCe.JianceShanghuaLeixing(room.desk_dong.shoupai, room.desk_dong.cpg, room.desk_dong.mopai);
                    Console.WriteLine("zmlx:" + shlx);
                    moPaiShuZi = room.desk_dong.mopai;
                }
                else if (player.playerPos == PlayerPosition.nan)
                {
                    shlx = jianCe.JianceShanghuaLeixing(room.desk_nan.shoupai, room.desk_nan.cpg, room.desk_nan.mopai);
                    Console.WriteLine("zmlx:" + shlx);
                    moPaiShuZi = room.desk_nan.mopai;
                }
                else if (player.playerPos == PlayerPosition.xi)
                {
                    shlx = jianCe.JianceShanghuaLeixing(room.desk_xi.shoupai, room.desk_xi.cpg, room.desk_xi.mopai);
                    Console.WriteLine("zmlx:" + shlx);
                    moPaiShuZi = room.desk_xi.mopai;
                }
                else if (player.playerPos == PlayerPosition.bei)
                {
                    shlx = jianCe.JianceShanghuaLeixing(room.desk_bei.shoupai, room.desk_bei.cpg, room.desk_bei.mopai);
                    Console.WriteLine("zmlx:" + shlx);
                    moPaiShuZi = room.desk_bei.mopai;
                }

                if (shlx == clientShangHuaLeiXing)
                {
                    Dictionary<short, object> dict_shanghuareturn = new Dictionary<short, object>();
                    dict_shanghuareturn.Add(1, shlx);
                    dict_shanghuareturn.Add(2, player.actorId);
                    dict_shanghuareturn.Add(3, moPaiShuZi);

                    dict_shanghuareturn.Add(4, room.desk_dong.shoupai);
                    dict_shanghuareturn.Add(5, room.desk_nan.shoupai);
                    dict_shanghuareturn.Add(6, room.desk_xi.shoupai);
                    dict_shanghuareturn.Add(7, room.desk_bei.shoupai);


                    //计算一下自摸分数，更新数据库上的分数，再返回给客户端：
                    //开始结算分数
                    JieSuan jiesuan = new JieSuan();

                    if (room.roomInfo.isYuePai)
                    {
                        int winfenshu = jiesuan.GetShangHuaScore(room.roomInfo.roomType, shlx, 1);

                        //先存储
                        //1.先更新赢玩家的积分                              
                        player.jiFen += winfenshu * 3;

                        //2.再更新输玩家，或放炮玩家的分数
                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            if (room.desklist[i].peer != this)
                            {
                                room.desklist[i].peer.player.jiFen -= winfenshu;
                            }
                        }

                        Console.WriteLine("东积分：" + room.desk_dong.peer.player.jiFen + "南积分：" + room.desk_nan.peer.player.jiFen + "西积分：" + room.desk_xi.peer.player.jiFen + "北积分：:" + room.desk_bei.peer.player.jiFen);

                        //保存每个桌子上的积分
                        room.desk_dong.jiFen = room.desk_dong.peer.player.jiFen;
                        room.desk_nan.jiFen = room.desk_nan.peer.player.jiFen;
                        room.desk_xi.jiFen = room.desk_xi.peer.player.jiFen;
                        room.desk_bei.jiFen = room.desk_bei.peer.player.jiFen;

                        int jiFen_dong = room.desk_dong.peer.player.jiFen;
                        int jiFen_nan = room.desk_nan.peer.player.jiFen;
                        int jiFen_xi = room.desk_xi.peer.player.jiFen;
                        int jiFen_bei = room.desk_bei.peer.player.jiFen;

                        dict_shanghuareturn.Add(8, jiFen_dong);
                        dict_shanghuareturn.Add(9, jiFen_nan);
                        dict_shanghuareturn.Add(10, jiFen_xi);
                        dict_shanghuareturn.Add(11, jiFen_bei);
                    }
                    else
                    {
                        Console.WriteLine("自摸时房间中的底分是：" + room.diFen);
                        int winfenshu = jiesuan.GetShangHuaScore(room.roomInfo.roomType, shlx, room.diFen);

                        //先存储
                        //1.先更新赢玩家的分数
                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            if (room.desklist[i].peer == this)
                            {
                                MySQLManager.UpdateCoin(winfenshu * 3, room.desklist[i].peer.userinfo.id);
                            }
                        }

                        //2.再更新输玩家，或放炮玩家的分数
                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            if (room.desklist[i].peer != this)
                            {
                                MySQLManager.UpdateCoin(-winfenshu, room.desklist[i].peer.userinfo.id);
                            }
                        }
                        for (int i = 0; i < room.desklist.Count; i++)
                        {
                            MySQLManager.UpdatejinriCoinJushu(1, room.desklist[i].peer.userinfo.id);
                            MySQLManager.UpdatejinriZongJushu(1, room.desklist[i].peer.userinfo.id);
                        }
                        //再查询
                        int coin_dong = MySQLManager.UseIDfindDiamond(room.desk_dong.peer.userinfo.id);
                        int coin_nan = MySQLManager.UseIDfindDiamond(room.desk_nan.peer.userinfo.id);
                        int coin_xi = MySQLManager.UseIDfindDiamond(room.desk_xi.peer.userinfo.id);
                        int coin_bei = MySQLManager.UseIDfindDiamond(room.desk_bei.peer.userinfo.id);
                        Console.WriteLine("coin_dong" + coin_dong + "coin_nan" + coin_nan + "coin_xi" + coin_xi + "coin_bei:" + coin_bei);

                        dict_shanghuareturn.Add(12, coin_dong);
                        dict_shanghuareturn.Add(13, coin_nan);
                        dict_shanghuareturn.Add(14, coin_xi);
                        dict_shanghuareturn.Add(15, coin_bei);
                    }


                    //胡、自摸、上花、抢杠后更新一下房间信息，做进一步判断，如果约牌局数到了就显示积分，结束约牌。
                    dict_shanghuareturn.Add(16, room.roomInfo);


                    for (int i = 0; i < room.desklist.Count; i++)
                    {
                        //room.deskList[i].peer.gamestate = GameState.score;                                
                    }
                    SendEventToAll(15, dict_shanghuareturn);

                    room.OnGameOver();
                    gamestate = GameState.score;

                    //gamestate = GameState.score;
                }
            }
            else if (opCode == 12) //暗杠，加杠的响应
            {
                test_number++;
                Console.WriteLine("当前进入了暗杠的方法" + test_number + "次");
                int gangpaishuzi = Converter<int>(dict[1]);
                ChiPengGangLeixing cpglx = Converter<ChiPengGangLeixing>(dict[2]);
                List<int> listHS = null;
                Desk desk = null;

                if (player.playerPos == PlayerPosition.dong)
                {
                    listHS = new List<int>(room.desk_dong.shoupai);
                    if (room.desk_dong.mopai != 0)
                    {
                        listHS.Add(room.desk_dong.mopai);
                    }
                    desk = room.desk_dong;
                }
                else if (player.playerPos == PlayerPosition.nan)
                {
                    listHS = new List<int>(room.desk_nan.shoupai);
                    if (room.desk_nan.mopai != 0)
                    {
                        listHS.Add(room.desk_nan.mopai);
                    }
                    desk = room.desk_nan;
                }
                else if (player.playerPos == PlayerPosition.xi)
                {
                    listHS = new List<int>(room.desk_xi.shoupai);
                    if (room.desk_xi.mopai != 0)
                    {
                        listHS.Add(room.desk_xi.mopai);
                    }
                    desk = room.desk_xi;
                }
                else if (player.playerPos == PlayerPosition.bei)
                {
                    listHS = new List<int>(room.desk_bei.shoupai);
                    if (room.desk_bei.mopai != 0)
                    {
                        listHS.Add(room.desk_bei.mopai);
                    }
                    desk = room.desk_bei;
                }
                if (cpglx == ChiPengGangLeixing.AnGang)
                {
                    Dictionary<int, int> dict_xiangtongpaishu = new Dictionary<int, int>();
                    foreach (var item in listHS)
                    {
                        if (dict_xiangtongpaishu.ContainsKey(item))
                        {
                            dict_xiangtongpaishu[item] += 1;
                        }
                        else
                        {
                            dict_xiangtongpaishu[item] = 1;
                        }
                    }
                    if (dict_xiangtongpaishu[gangpaishuzi] == 4)
                    {
                        if (desk.mopai != 0)
                        {
                            desk.shoupai.Add(desk.mopai);
                            desk.mopai = 0;
                        }
                        int shoupaicount = desk.shoupai.Count;
                        for (int i = 0; i < shoupaicount; i++)
                        {
                            for (int j = 0; j < desk.shoupai.Count; j++)
                            {
                                if (desk.shoupai[j] == gangpaishuzi)
                                {
                                    desk.shoupai.RemoveAt(j);
                                    break;
                                }
                            }
                        }
                        desk.cpg.Add(new CPGProperties() { cpglist = new List<int>() { gangpaishuzi, gangpaishuzi, gangpaishuzi, gangpaishuzi }, cpglx = ChiPengGangLeixing.AnGang });
                        int mopai = 0;
                        if (room.queue_pai.Count > 0)
                        {
                            mopai = room.queue_pai.Dequeue();
                        }
                        else//当牌没有了时，说明黄牌了，需要发送一个事件给所有人，告诉他们黄牌，并结束
                        {
                            room.OnHuangPai();

                            return;
                        }
                        if (player.playerPos == PlayerPosition.dong)
                        {
                            room.desk_dong.mopai = mopai;
                            room.desk_nan.mopai = 0;
                            room.desk_xi.mopai = 0;
                            room.desk_bei.mopai = 0;
                        }
                        else if (player.playerPos == PlayerPosition.nan)
                        {
                            room.desk_dong.mopai = 0;
                            room.desk_nan.mopai = mopai;
                            room.desk_xi.mopai = 0;
                            room.desk_bei.mopai = 0;
                        }
                        else if (player.playerPos == PlayerPosition.xi)
                        {
                            room.desk_dong.mopai = 0;
                            room.desk_nan.mopai = 0;
                            room.desk_xi.mopai = mopai;
                            room.desk_bei.mopai = 0;
                        }
                        else if (player.playerPos == PlayerPosition.bei)
                        {
                            room.desk_dong.mopai = 0;
                            room.desk_nan.mopai = 0;
                            room.desk_xi.mopai = 0;
                            room.desk_bei.mopai = mopai;
                        }
                        if (mopai != 0)
                        {
                            Dictionary<short, object> dict_response = new Dictionary<short, object>();
                            dict_response.Add(1, gangpaishuzi);
                            dict_response.Add(2, cpglx);
                            dict_response.Add(3, mopai);
                            dict_response.Add(4, player.actorId);
                            dict_response.Add(5, room.queue_pai.Count);
                            room.needChuPaiID = player.actorId;
                            room.isganghouchupai = true;
                            SendEventToAll(16, dict_response);
                            SendEventToAll(19, null);
                            room.timer_NeedChuPaiJiShi.Stop();
                            room.timer_NeedChuPaiJiShi.Start();
                            room.anGangJiaGangID = player.actorId;
                        }
                        else
                        {
                            Dictionary<short, object> dict_response = new Dictionary<short, object>();
                            dict_response.Add(1, "获取摸牌失败");

                        }
                    }
                }
                else if (cpglx == ChiPengGangLeixing.Gang)
                {
                    bool temp = false;
                    if (listHS.Contains(gangpaishuzi))
                    {
                        foreach (var item in desk.cpg)
                        {
                            if (item.cpglx == ChiPengGangLeixing.Peng)
                            {
                                if (item.cpglist[0] == gangpaishuzi)
                                {
                                    temp = true;
                                }
                            }
                        }
                    }
                    if (temp == true)
                    {
                        if (desk.mopai != 0)
                        {
                            desk.shoupai.Add(desk.mopai);
                            desk.mopai = 0;
                        }
                        for (int i = 0; i < desk.shoupai.Count; i++)
                        {
                            if (desk.shoupai[i] == gangpaishuzi)
                            {
                                desk.shoupai.RemoveAt(i);
                                break;
                            }
                        }
                        for (int i = 0; i < desk.cpg.Count; i++)
                        {
                            if (desk.cpg[i].cpglist[0] == gangpaishuzi)
                            {
                                desk.cpg[i].cpglist.Add(gangpaishuzi);
                                desk.cpg[i].cpglx = ChiPengGangLeixing.Gang;
                            }
                        }
                        int mopai = 0;
                        Dictionary<short, object> dict_shoupaigangData = new Dictionary<short, object>();
                        dict_shoupaigangData.Add(1, gangpaishuzi);
                        dict_shoupaigangData.Add(2, cpglx);
                        dict_shoupaigangData.Add(3, mopai);
                        dict_shoupaigangData.Add(4, player.actorId);
                        dict_shoupaigangData.Add(5, room.queue_pai.Count);
                        SendEventToAll(16, dict_shoupaigangData);

                        room.list_qiangGangReturn.Clear();
                        room.isExcutedChuPaiDataReturn = false;
                        room.desk_dong.isQiangGangReturn = false;
                        room.desk_nan.isQiangGangReturn = false;
                        room.desk_xi.isQiangGangReturn = false;
                        room.desk_bei.isQiangGangReturn = false;
                        desk.isQiangGangReturn = true;

                        if (room.desk_dong.peer.IsConnected == false)
                        {
                            room.desk_dong.isQiangGangReturn = true;
                        }
                        if (room.desk_nan.peer.IsConnected == false)
                        {
                            room.desk_nan.isQiangGangReturn = true;
                        }
                        if (room.desk_xi.peer.IsConnected == false)
                        {
                            room.desk_xi.isQiangGangReturn = true;
                        }
                        if (room.desk_bei.peer.IsConnected == false)
                        {
                            room.desk_bei.isQiangGangReturn = true;
                        }

                        Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                        if (player.playerPos == PlayerPosition.dong)
                        {
                            Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_nan);
                            room.desk_nan.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_xi);
                            room.desk_xi.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_bei);
                            room.desk_bei.peer.SendEvent(17, dict_ev);
                        }  //判断刚刚出牌的人是谁，让除他之外的所有人看看自己能否胡牌，碰牌，杠牌
                        else if (player.playerPos == PlayerPosition.nan)
                        {
                            Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, gangpaishuzi, false, true);
                            Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                            dict_ev.Add(1, hplx_xi);
                            room.desk_xi.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_bei);
                            room.desk_bei.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_dong);
                            room.desk_dong.peer.SendEvent(17, dict_ev);
                        }
                        else if (player.playerPos == PlayerPosition.xi)
                        {
                            Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_bei);
                            room.desk_bei.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_dong);
                            room.desk_dong.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_nan);
                            room.desk_nan.peer.SendEvent(17, dict_ev);
                        }
                        else if (player.playerPos == PlayerPosition.bei)
                        {
                            Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_dong);
                            room.desk_dong.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_nan);
                            room.desk_nan.peer.SendEvent(17, dict_ev);

                            Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, gangpaishuzi, false, true);
                            dict_ev.Add(1, hplx_xi);
                            room.desk_xi.peer.SendEvent(17, dict_ev);
                        }
                        room.timer_NeedChuPaiJiShi.Stop();

                        //发送完数据后，需要开启房间中的抢杠计时
                        room.timer_QiangGangReturnJiShi.Start();

                        //更新一下暗杠加杠的ID
                        room.anGangJiaGangID = player.actorId;
                        SendEventToAll(19, null);

                    }
                }
            }
            else if (opCode == 13)
            {
                Desk desk = new Desk();
                Hupaileixing qiangGangLeiXing = Converter<Hupaileixing>(dict[1]);
                if (qiangGangLeiXing != Hupaileixing.buhu)
                {
                    QiangGangReturnData qiangGangReturnData = new QiangGangReturnData() { huPaiActorID = player.actorId, hplx_qiangGang = qiangGangLeiXing };
                    room.list_qiangGangReturn.Add(qiangGangReturnData);
                }
                if (player.playerPos == PlayerPosition.dong)
                {
                    desk = room.desk_dong;
                }
                else if (player.playerPos == PlayerPosition.nan)
                {
                    desk = room.desk_nan;
                }
                else if (player.playerPos == PlayerPosition.xi)
                {
                    desk = room.desk_xi;
                }
                else if (player.playerPos == PlayerPosition.bei)
                {
                    desk = room.desk_bei;
                }
                desk.isQiangGangReturn = true;
                if ((room.desk_dong.isChuPaiReturn || room.desk_dong.peer.IsConnected == false) &&
                    (room.desk_nan.isChuPaiReturn || room.desk_nan.peer.IsConnected == false) &&
                    (room.desk_xi.isChuPaiReturn || room.desk_xi.peer.IsConnected == false) &&
                    (room.desk_bei.isChuPaiReturn || room.desk_bei.peer.IsConnected == false))
                {
                    room.QiangGangDataReturn();
                }
            }//抢杠
            else if (opCode == 14) //代理摸牌
            {
                bool isGangHouMoPai = Converter<bool>(dict[1]);
                int nextmopaiID = Converter<int>(dict[2]);

                int mopai = 0;
                if (room.queue_pai.Count > 0)
                {
                    mopai = room.queue_pai.Dequeue();
                }
                else//当牌没有了时，说明黄牌了，需要发送一个事件给所有人，告诉他们黄牌，并结束
                {
                    room.OnHuangPai();

                    return;
                }


                Desk mopaiDesk = null;
                for (int i = 0; i < room.desklist.Count; i++)
                {
                    if (room.desklist[i].peer.player.actorId == nextmopaiID)
                    {
                        //moPaiPeer = room.deskList[i].peer;
                        mopaiDesk = room.desklist[i];
                    }
                }


                if (mopai != 0)
                {
                    //当摸起牌来后，就直接出牌，需要出牌的ID就是玩家ID
                    room.needChuPaiID = nextmopaiID;
                    room.isganghouchupai = isGangHouMoPai;

                    room.chuPaiID = nextmopaiID;
                    room.chupaishuzi = mopai;

                    //出完牌后，各个玩家选择期间暂时不需要有人出牌，设置为0
                    room.needChuPaiID = 0;


                    //第一步，更新各自牌属性，第二步，检测胡、杠、碰、吃。                        
                    //moPaiPeer.desk.throwPai.Add(mopai);
                    mopaiDesk.throwpai.Add(mopai);

                    room.isExcutedChuPaiDataReturn = false;

                    ////重置房间中4个桌子的出牌操作，出牌的人设置为true
                    ////当吃碰后的出牌必需设置开关，不然会出错（当其他家能吃碰杠时，下家会开始摸牌）
                    room.desk_dong.isChuPaiReturn = false;
                    room.desk_nan.isChuPaiReturn = false;
                    room.desk_xi.isChuPaiReturn = false;
                    room.desk_bei.isChuPaiReturn = false;
                    ////上面四个属性在摸牌时也被设置为false

                    mopaiDesk.isChuPaiReturn = true;

                    //为了防止玩家掉线重连后，没有正确返回
                    if (room.desk_dong.peer.IsConnected == false)
                    {
                        room.desk_dong.isChuPaiReturn = true;
                    }
                    if (room.desk_xi.peer.IsConnected == false)
                    {
                        room.desk_xi.isChuPaiReturn = true;
                    }
                    if (room.desk_nan.peer.IsConnected == false)
                    {
                        room.desk_nan.isChuPaiReturn = true;
                    }
                    if (room.desk_bei.peer.IsConnected == false)
                    {
                        room.desk_bei.isChuPaiReturn = true;
                    }

                    room.list_huReturn.Clear();
                    room.list_pgReturn.Clear();
                    room.list_chiReturn.Clear();

                    Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                    dict_ev.Add(4, mopai);//告诉其他玩家出了哪张牌
                    //dict_ev.Add(2, mopaiDesk.peer.player.actorId);//告诉其他玩家是谁出了牌

                    //发送的响应dict中包含1.牌的数字，2.胡的类型，3.吃的类型（list，如果list。count为0 ，则不吃），4.碰杠的类型：碰、可碰可杠

                    if (mopaiDesk.peer.player.playerPos == PlayerPosition.dong)
                    {
                        Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_nan = jianCe.JiancePenggangLeixing(room.desk_nan, mopai);
                        List<int> listchi_nan = jianCe.JianCeXiajiachi(room.desk_nan, mopai);
                        Dictionary<short, object> paileiXing_nan = new Dictionary<short, object>();
                        paileiXing_nan.Add(1, hplx_nan);
                        paileiXing_nan.Add(2, pglx_nan);
                        paileiXing_nan.Add(3, listchi_nan);
                        paileiXing_nan.Add(4, mopai);
                        if (room.desk_nan.peer != null && room.desk_nan.peer.IsConnected)
                        {
                            room.desk_nan.peer.SendEvent(7, paileiXing_nan);
                        }


                        Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_xi = jianCe.JiancePenggangLeixing(room.desk_xi, mopai);
                        List<int> listchi_xi = null;
                        Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                        paileiXing_xi.Add(1, hplx_xi);
                        paileiXing_xi.Add(2, pglx_xi);
                        paileiXing_xi.Add(3, listchi_xi);
                        paileiXing_xi.Add(4, mopai);
                        if (room.desk_xi.peer != null && room.desk_xi.peer.IsConnected)
                        {
                            room.desk_xi.peer.SendEvent(7, paileiXing_xi);
                        }


                        Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_bei = jianCe.JiancePenggangLeixing(room.desk_bei, mopai);
                        List<int> listchi_bei = null;
                        Dictionary<short, object> paileiXing_bei = new Dictionary<short, object>();
                        paileiXing_bei.Add(1, hplx_bei);
                        paileiXing_bei.Add(2, pglx_bei);
                        paileiXing_bei.Add(3, listchi_bei);
                        paileiXing_bei.Add(4, mopai);
                        if (room.desk_bei.peer != null && room.desk_bei.peer.IsConnected)
                        {
                            room.desk_bei.peer.SendEvent(7, paileiXing_bei);
                        }

                    }  //判断刚刚出牌的人是谁，让除他之外的所有人看看自己能否胡牌，碰牌，杠牌
                    else if (mopaiDesk.peer.player.playerPos == PlayerPosition.nan)
                    {
                        Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_xi = jianCe.JiancePenggangLeixing(room.desk_xi, mopai);
                        List<int> listchi_xi = jianCe.JianCeXiajiachi(room.desk_xi, mopai);
                        Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                        paileiXing_xi.Add(1, hplx_xi);
                        paileiXing_xi.Add(2, pglx_xi);
                        paileiXing_xi.Add(3, listchi_xi);
                        paileiXing_xi.Add(4, mopai);
                        if (room.desk_xi.peer != null && room.desk_xi.peer.IsConnected)
                        {
                            room.desk_xi.peer.SendEvent(7, paileiXing_xi);
                        }


                        Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_bei = jianCe.JiancePenggangLeixing(room.desk_bei, mopai);
                        List<int> listchi_bei = null;
                        Dictionary<short, object> paileiXing_bei = new Dictionary<short, object>();
                        paileiXing_bei.Add(1, hplx_bei);
                        paileiXing_bei.Add(2, pglx_bei);
                        paileiXing_bei.Add(3, listchi_bei);
                        paileiXing_bei.Add(4, mopai);
                        if (room.desk_bei.peer != null && room.desk_bei.peer.IsConnected)
                        {
                            room.desk_bei.peer.SendEvent(7, paileiXing_bei);
                        }


                        Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_dong = jianCe.JiancePenggangLeixing(room.desk_dong, mopai);
                        List<int> listchi_dong = null;
                        Dictionary<short, object> paileiXing_dong = new Dictionary<short, object>();
                        paileiXing_dong.Add(1, hplx_dong);
                        paileiXing_dong.Add(2, pglx_dong);
                        paileiXing_dong.Add(3, listchi_dong);
                        paileiXing_dong.Add(4, mopai);
                        if (room.desk_dong.peer != null && room.desk_dong.peer.IsConnected)
                        {
                            room.desk_dong.peer.SendEvent(7, paileiXing_dong);
                        }

                    }
                    else if (mopaiDesk.peer.player.playerPos == PlayerPosition.xi)
                    {
                        Hupaileixing hplx_bei = jianCe.JianCeHuPaiLeiXing(room.desk_bei, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_bei = jianCe.JiancePenggangLeixing(room.desk_bei, mopai);
                        List<int> listchi_bei = jianCe.JianCeXiajiachi(room.desk_bei, mopai);
                        Dictionary<short, object> paileiXing_bei = new Dictionary<short, object>();
                        paileiXing_bei.Add(1, hplx_bei);
                        paileiXing_bei.Add(2, pglx_bei);
                        paileiXing_bei.Add(3, listchi_bei);
                        paileiXing_bei.Add(4, mopai);

                        if (room.desk_bei.peer != null && room.desk_bei.peer.IsConnected)
                        {
                            room.desk_bei.peer.SendEvent(7, paileiXing_bei);
                        }


                        Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_dong = jianCe.JiancePenggangLeixing(room.desk_dong, mopai);
                        List<int> listchi_dong = null;
                        Dictionary<short, object> paileiXing_dong = new Dictionary<short, object>();
                        paileiXing_dong.Add(1, hplx_dong);
                        paileiXing_dong.Add(2, pglx_dong);
                        paileiXing_dong.Add(3, listchi_dong);
                        paileiXing_dong.Add(4, mopai);
                        if (room.desk_dong.peer != null && room.desk_dong.peer.IsConnected)
                        {
                            room.desk_dong.peer.SendEvent(7, paileiXing_dong);
                        }


                        Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_nan = jianCe.JiancePenggangLeixing(room.desk_nan, mopai);
                        List<int> listchi_nan = null;
                        Dictionary<short, object> paileiXing_nan = new Dictionary<short, object>();
                        paileiXing_nan.Add(1, hplx_nan);
                        paileiXing_nan.Add(2, pglx_nan);
                        paileiXing_nan.Add(3, listchi_nan);
                        paileiXing_nan.Add(4, mopai);
                        if (room.desk_nan.peer != null && room.desk_nan.peer.IsConnected)
                        {
                            room.desk_nan.peer.SendEvent(7, paileiXing_nan);
                        }

                    }
                    else if (mopaiDesk.peer.player.playerPos == PlayerPosition.bei)
                    {
                        Hupaileixing hplx_dong = jianCe.JianCeHuPaiLeiXing(room.desk_dong, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_dong = jianCe.JiancePenggangLeixing(room.desk_dong, mopai);
                        List<int> listchi_dong = jianCe.JianCeXiajiachi(room.desk_dong, mopai);
                        Dictionary<short, object> paileiXing_dong = new Dictionary<short, object>();
                        paileiXing_dong.Add(1, hplx_dong);
                        paileiXing_dong.Add(2, pglx_dong);
                        paileiXing_dong.Add(3, listchi_dong);
                        paileiXing_dong.Add(4, mopai);
                        if (room.desk_dong.peer != null && room.desk_dong.peer.IsConnected)
                        {
                            room.desk_dong.peer.SendEvent(7, paileiXing_dong);
                        }


                        Hupaileixing hplx_nan = jianCe.JianCeHuPaiLeiXing(room.desk_nan, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_nan = jianCe.JiancePenggangLeixing(room.desk_nan, mopai);
                        List<int> listchi_nan = null;
                        Dictionary<short, object> paileiXing_nan = new Dictionary<short, object>();
                        paileiXing_nan.Add(1, hplx_nan);
                        paileiXing_nan.Add(2, pglx_nan);
                        paileiXing_nan.Add(3, listchi_nan);
                        paileiXing_nan.Add(4, mopai);
                        if (room.desk_nan.peer != null && room.desk_nan.peer.IsConnected)
                        {
                            room.desk_nan.peer.SendEvent(7, paileiXing_nan);
                        }


                        Hupaileixing hplx_xi = jianCe.JianCeHuPaiLeiXing(room.desk_xi, mopai, isGangHouMoPai, false);
                        PengGangLeixing pglx_xi = jianCe.JiancePenggangLeixing(room.desk_xi, mopai);
                        List<int> listchi_xi = null;
                        Dictionary<short, object> paileiXing_xi = new Dictionary<short, object>();
                        paileiXing_xi.Add(1, hplx_xi);
                        paileiXing_xi.Add(2, pglx_xi);
                        paileiXing_xi.Add(3, listchi_xi);
                        paileiXing_xi.Add(4, mopai);
                        if (room.desk_xi.peer != null && room.desk_xi.peer.IsConnected)
                        {
                            room.desk_xi.peer.SendEvent(7, paileiXing_xi);
                        }

                    }

                    //发送一个事件给房间中的所有人开启10秒计时                       
                    SendEventToAll(19, null);
                    Dictionary<short, object> PaiMessage = new Dictionary<short, object>();
                    PaiMessage.Add(1, mopaiDesk.peer.player.actorId);
                    PaiMessage.Add(2, mopai);
                    PaiMessage.Add(3, true);
                    Console.WriteLine("发送出去的ID是" + mopaiDesk.peer.player.actorId);
                    for (int j = 0; j < room.desklist.Count; j++)
                    {
                        if (room.desklist[j].peer != null && room.desklist[j].peer.IsConnected)
                        {
                            room.desklist[j].peer.SendEvent(6, PaiMessage);
                        }
                    }

                    //开启出牌返回计时
                    room.timer_ChuPaiReturnJiShi.Start();
                }
                //else
                //{
                //    Dictionary<short, object> dict_response = new Dictionary<short, object>();
                //    dict_response.Add(ParameterCode.error, "代理摸牌失败");
                //    SendResponse(opCode, ReturnCode.fail, dict_response);
                //}
            }
            else if (opCode == 15)//检测是否需要重新进入房间
            {
                List<Room> listroom = new List<Room>();
                foreach (var item in AllGames.dict_rooms.Values)
                {
                    listroom.Add(item);
                }
                foreach (var item in AllGames.dict_rooms_tongYongMJ_coin.Values)
                {
                    listroom.Add(item);
                }

                bool isExistID = false;//是否存在玩家ID
                for (int i = 0; i < listroom.Count; i++)
                {
                    if (listroom[i].desk_dong.isJoin && listroom[i].desk_dong.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        break;
                    }
                    else if (listroom[i].desk_nan.isJoin && listroom[i].desk_nan.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        break;
                    }
                    else if (listroom[i].desk_xi.isJoin && listroom[i].desk_xi.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        break;
                    }
                    else if (listroom[i].desk_bei.isJoin && listroom[i].desk_bei.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        break;
                    }
                }

                Dictionary<short, object> dict_response = new Dictionary<short, object>();
                dict_response.Add(1, isExistID);
                SendResponse(8, ReturnCode.success, dict_response);
            }
            else if (opCode == 16) //玩家选择了要重新链接
            {
                List<Room> listroom = new List<Room>();
                foreach (var item in AllGames.dict_rooms.Values)
                {
                    listroom.Add(item);
                }
                foreach(var item in AllGames.dict_rooms_tongYongMJ_coin.Values)
                {
                    listroom.Add(item);
                }

                bool isExistID = false;//是否存在玩家ID
                for (int i = 0; i < listroom.Count; i++)
                {
                    if (listroom[i].desk_dong.isJoin && listroom[i].desk_dong.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        room = listroom[i];
                        player = room.desk_dong.peer.player;
                        joinDesk = room.desk_dong;
                        player.actorId = room.desk_dong.peer.player.actorId;
                        player.playerPos = PlayerPosition.dong;

                        this.gamestate = room.desk_dong.peer.gamestate;

                        room.desk_dong.peer = this;

                        break;
                    }
                    else if (listroom[i].desk_nan.isJoin && listroom[i].desk_nan.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        room = listroom[i];
                        player = room.desk_nan.peer.player;
                        joinDesk = room.desk_nan;
                        player.actorId = room.desk_nan.peer.player.actorId;
                        player.playerPos = PlayerPosition.nan;

                        this.gamestate = room.desk_nan.peer.gamestate;

                        room.desk_nan.peer = this;

                        break;
                    }
                    else if (listroom[i].desk_xi.isJoin && listroom[i].desk_xi.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        room = listroom[i];
                        player = room.desk_xi.peer.player;
                        joinDesk = room.desk_xi;
                        player.actorId = room.desk_xi.peer.player.actorId;
                        player.playerPos = PlayerPosition.xi;

                        this.gamestate = room.desk_xi.peer.gamestate;

                        room.desk_xi.peer = this;

                        break;
                    }
                    else if (listroom[i].desk_bei.isJoin && listroom[i].desk_bei.peer.userinfo.id == userinfo.id)
                    {
                        isExistID = true;
                        room = listroom[i];
                        player = room.desk_bei.peer.player;
                        joinDesk = room.desk_bei;
                        player.actorId = room.desk_bei.peer.player.actorId;
                        player.playerPos = PlayerPosition.bei;

                        this.gamestate = room.desk_bei.peer.gamestate;

                        room.desk_bei.peer = this;

                        break;
                    }
                }

                Console.WriteLine("isExistID:" + isExistID + "是否在线：" + this.IsConnected);
                if (isExistID)//如果存在玩家ID，说明需要重新加入房间
                {
                    Dictionary<short, object> dict_response = new Dictionary<short, object>();
                    dict_response.Add(1, room.roomInfo);
                    dict_response.Add(2, player);

                    //把房间中的所有玩家的手牌、摸牌、抛牌、吃碰杠牌

                    DeskInfo deskinfo_benjia = new DeskInfo();
                    deskinfo_benjia.shoupai = joinDesk.shoupai;
                    deskinfo_benjia.mopai = joinDesk.mopai;
                    deskinfo_benjia.throwPai = joinDesk.throwpai;
                    deskinfo_benjia.cpg = joinDesk.cpg;

                    dict_response.Add(3, deskinfo_benjia);

                    //把房间中玩家是否需要出牌的属性发给玩家
                    //分三种情况：1有摸牌需要出牌；2没有摸牌需要出牌；3没有摸牌不需要出牌。
                    Console.WriteLine("房间中需要出牌玩家ID是：" + room.needChuPaiID + "  player的ID是" + player.actorId);
                    if (room.needChuPaiID == player.actorId)//当需要出牌玩家和玩家ID相等时，就说明需要出牌
                    {

                        dict_response.Add(4, true);
                    }
                    else
                    {
                        dict_response.Add(4, false);
                    }

                    //重进游戏时重置时间
                    if (room.needChuPaiID != 0)
                    {
                        room.timer_NeedChuPaiJiShi.Stop();
                        Console.WriteLine("房间出牌计时关闭");
                        room.timer_NeedChuPaiJiShi.Start();
                        Console.WriteLine("房间出牌计时开启");
                    }

                    //
                    if (room.desk_dong.isChuPaiReturn == false || room.desk_nan.isChuPaiReturn == false
                        || room.desk_xi.isChuPaiReturn == false || room.desk_bei.isChuPaiReturn == false)//还在有问题，控制不准确
                    {
                        room.timer_ChuPaiReturnJiShi.Stop();
                        Console.WriteLine("出牌返回计时关闭");
                        //MyLog.Log("出牌返回计时关闭");
                        room.timer_ChuPaiReturnJiShi.Start();
                        Console.WriteLine("出牌返回计时开启");
                       // MyLog.Log("出牌返回计时开启");
                    }

                    if (room.desk_dong.isQiangGangReturn == false || room.desk_nan.isQiangGangReturn == false
                       || room.desk_xi.isQiangGangReturn == false || room.desk_bei.isQiangGangReturn == false)
                    {
                        room.timer_QiangGangReturnJiShi.Stop();
                        Console.WriteLine("抢杠返回计时关闭");
                        room.timer_QiangGangReturnJiShi.Start();
                        Console.WriteLine("抢杠返回计时开启");
                    }

                    //把房间中的其他玩家的属性发给本人
                    if (player.playerPos == PlayerPosition.dong)
                    {//如果玩家是东，就把南西北玩家属性发给本人
                        dict_response.Add(5, room.desk_nan.peer.player);
                        DeskInfo deskinfo_xiajia = new DeskInfo();
                        deskinfo_xiajia.shoupai = room.desk_nan.shoupai;
                        deskinfo_xiajia.mopai = room.desk_nan.mopai;
                        deskinfo_xiajia.throwPai = room.desk_nan.throwpai;
                        deskinfo_xiajia.cpg = room.desk_nan.cpg;
                        dict_response.Add(6, deskinfo_xiajia);

                        dict_response.Add(7, room.desk_xi.peer.player);
                        DeskInfo deskinfo_duijia = new DeskInfo();
                        deskinfo_duijia.shoupai = room.desk_xi.shoupai;
                        deskinfo_duijia.mopai = room.desk_xi.mopai;
                        deskinfo_duijia.throwPai = room.desk_xi.throwpai;
                        deskinfo_duijia.cpg = room.desk_xi.cpg;
                        dict_response.Add(8, deskinfo_duijia);

                        dict_response.Add(9, room.desk_bei.peer.player);
                        DeskInfo deskinfo_shangjia = new DeskInfo();
                        deskinfo_shangjia.shoupai = room.desk_bei.shoupai;
                        deskinfo_shangjia.mopai = room.desk_bei.mopai;
                        deskinfo_shangjia.throwPai = room.desk_bei.throwpai;
                        deskinfo_shangjia.cpg = room.desk_bei.cpg;
                        dict_response.Add(10, deskinfo_shangjia);
                    }
                    else if (player.playerPos == PlayerPosition.nan)
                    {
                        //如果玩家是南，就把东西北玩家属性发给本人
                        dict_response.Add(5, room.desk_xi.peer.player);
                        DeskInfo deskinfo_xiajia = new DeskInfo();
                        deskinfo_xiajia.shoupai = room.desk_xi.shoupai;
                        deskinfo_xiajia.mopai = room.desk_xi.mopai;
                        deskinfo_xiajia.throwPai = room.desk_xi.throwpai;
                        deskinfo_xiajia.cpg = room.desk_xi.cpg;
                        dict_response.Add(6, deskinfo_xiajia);

                        dict_response.Add(7, room.desk_bei.peer.player);
                        DeskInfo deskinfo_duijia = new DeskInfo();
                        deskinfo_duijia.shoupai = room.desk_bei.shoupai;
                        deskinfo_duijia.mopai = room.desk_bei.mopai;
                        deskinfo_duijia.throwPai = room.desk_bei.throwpai;
                        deskinfo_duijia.cpg = room.desk_bei.cpg;
                        dict_response.Add(8, deskinfo_duijia);

                        dict_response.Add(9, room.desk_dong.peer.player);
                        DeskInfo deskinfo_shangjia = new DeskInfo();
                        deskinfo_shangjia.shoupai = room.desk_dong.shoupai;
                        deskinfo_shangjia.mopai = room.desk_dong.mopai;
                        deskinfo_shangjia.throwPai = room.desk_dong.throwpai;
                        deskinfo_shangjia.cpg = room.desk_dong.cpg;
                        dict_response.Add(10, deskinfo_shangjia);
                    }
                    else if (player.playerPos == PlayerPosition.xi)
                    {//如果玩家是西，就把东南北玩家属性发给本人
                        dict_response.Add(5, room.desk_bei.peer.player);
                        DeskInfo deskinfo_xiajia = new DeskInfo();
                        deskinfo_xiajia.shoupai = room.desk_bei.shoupai;
                        deskinfo_xiajia.mopai = room.desk_bei.mopai;
                        deskinfo_xiajia.throwPai = room.desk_bei.throwpai;
                        deskinfo_xiajia.cpg = room.desk_bei.cpg;
                        dict_response.Add(6, deskinfo_xiajia);

                        dict_response.Add(7, room.desk_dong.peer.player);
                        DeskInfo deskinfo_duijia = new DeskInfo();
                        deskinfo_duijia.shoupai = room.desk_dong.shoupai;
                        deskinfo_duijia.mopai = room.desk_dong.mopai;
                        deskinfo_duijia.throwPai = room.desk_dong.throwpai;
                        deskinfo_duijia.cpg = room.desk_dong.cpg;
                        dict_response.Add(8, deskinfo_duijia);

                        dict_response.Add(9, room.desk_nan.peer.player);
                        DeskInfo deskinfo_shangjia = new DeskInfo();
                        deskinfo_shangjia.shoupai = room.desk_nan.shoupai;
                        deskinfo_shangjia.mopai = room.desk_nan.mopai;
                        deskinfo_shangjia.throwPai = room.desk_nan.throwpai;
                        deskinfo_shangjia.cpg = room.desk_nan.cpg;
                        dict_response.Add(10, deskinfo_shangjia);
                    }
                    else if (player.playerPos == PlayerPosition.bei)
                    {//如果玩家是北，就把东南西玩家属性发给本人
                        dict_response.Add(5, room.desk_dong.peer.player);
                        DeskInfo deskinfo_xiajia = new DeskInfo();
                        deskinfo_xiajia.shoupai = room.desk_dong.shoupai;
                        deskinfo_xiajia.mopai = room.desk_dong.mopai;
                        deskinfo_xiajia.throwPai = room.desk_dong.throwpai;
                        deskinfo_xiajia.cpg = room.desk_dong.cpg;
                        dict_response.Add(6, deskinfo_xiajia);

                        dict_response.Add(7, room.desk_nan.peer.player);
                        DeskInfo deskinfo_duijia = new DeskInfo();
                        deskinfo_duijia.shoupai = room.desk_nan.shoupai;
                        deskinfo_duijia.mopai = room.desk_nan.mopai;
                        deskinfo_duijia.throwPai = room.desk_nan.throwpai;
                        deskinfo_duijia.cpg = room.desk_nan.cpg;
                        dict_response.Add(8, deskinfo_duijia);

                        dict_response.Add(9, room.desk_xi.peer.player);
                        DeskInfo deskinfo_shangjia = new DeskInfo();
                        deskinfo_shangjia.shoupai = room.desk_xi.shoupai;
                        deskinfo_shangjia.mopai = room.desk_xi.mopai;
                        deskinfo_shangjia.throwPai = room.desk_xi.throwpai;
                        deskinfo_shangjia.cpg = room.desk_xi.cpg;
                        dict_response.Add(10, deskinfo_shangjia);
                    }

                    string str = JsonConvert.SerializeObject(dict_response);
                    byte[] strbytes = Encoding.UTF8.GetBytes(str);
                    Console.WriteLine("Rejoinroom中strbytes.length:" + strbytes.Length);

                    SendResponse(9, ReturnCode.success, dict_response);
                    Console.WriteLine("向玩家" + userinfo.id + "发送了响应JianCeReJoinRoom");

                    //加入房间后发送一个事件给房间里的其他人，告诉他们加入事件
                    //也就是把本人的属性发给其他人

                    Dictionary<short, object> dict_event = new Dictionary<short, object>();
                    //dict_event.Add(ParameterCode.playerActorid, player.actorId );//玩家有更多属性可以同时发送
                    dict_event.Add(1, player);
                    dict_event.Add(2, room.roomInfo);
                    for (int i = 0; i < room.desklist.Count; i++)
                    {
                        if (room.desklist[i].peer != this)
                        {
                            if (room.desklist[i].peer != null && room.desklist[i].peer.IsConnected)
                            {
                                room.desklist[i].peer.SendEvent(23, dict_event);
                            }
                        }
                    }
                }
            }
            else if (opCode == 17) //实现匹配模式
            {
                bool isKeChi = Converter<bool>(dict[1]);
                GameLevel gameLevel = Converter<GameLevel>(dict[2]);

                //找一找AllGames.dict_rooms_tongYongMJ_coin中有没有空位置，如果有则加入进去，如果没有就创建一个

                bool isYouKong = false;
                foreach (var item in AllGames.dict_rooms_tongYongMJ_coin.Values)
                {
                    if (item.desk_dong.isJoin == false)
                    {
                        room = item;
                        joinDesk = item.desk_dong;
                        item.desk_dong.peer = this;
                        item.desk_dong.isJoin = true;
                        player.playerPos = PlayerPosition.dong;

                        item.AllActorCount++;
                        player.actorId = item.AllActorCount;
                        player.isReady = false;

                        isYouKong = true;
                        break;
                    }
                    else if (item.desk_nan.isJoin == false)
                    {
                        room = item;
                        joinDesk = item.desk_nan;

                        item.desk_nan.peer = this;
                        item.desk_nan.isJoin = true;
                        player.playerPos = PlayerPosition.nan;

                        item.AllActorCount++;
                        player.actorId = item.AllActorCount;
                        player.isReady = false;

                        isYouKong = true;
                        break;
                    }
                    else if (item.desk_xi.isJoin == false)
                    {
                        room = item;
                        joinDesk = item.desk_xi;
                        item.desk_xi.peer = this;
                        item.desk_xi.isJoin = true;
                        player.playerPos = PlayerPosition.xi;

                        item.AllActorCount++;
                        player.actorId = item.AllActorCount;
                        player.isReady = false;

                        isYouKong = true;
                        break;
                    }
                    else if (item.desk_bei.isJoin == false)
                    {
                        room = item;
                        joinDesk = item.desk_bei;
                        item.desk_bei.peer = this;
                        item.desk_bei.isJoin = true;
                        player.playerPos = PlayerPosition.bei;

                        item.AllActorCount++;
                        player.actorId = item.AllActorCount;
                        player.isReady = false;

                        isYouKong = true;
                        break;
                    }
                }

                if (isYouKong == true)//如果房间有空
                {
                    Dictionary<short, object> dict_res = new Dictionary<short, object>();

                    dict_res.Add(1, room.roomInfo);

                    dict_res.Add(2, player);//把玩家的属性传出去

                    // 其他人的属性
                    List<Player> list = new List<Player>();

                    for (int i = 0; i < room.desklist.Count; i++)
                    {
                        if (room.desklist[i].isJoin)
                        {
                            list.Add(room.desklist[i].peer.player);
                        }
                    }

                    dict_res.Add(3, list);

                    SendResponse(10, ReturnCode.success, dict_res);

                    //发送一个事件给房间中其他人，有玩家加入事件
                    Dictionary<short, object> dict_ev = new Dictionary<short, object>();
                    dict_ev.Add(1, player);
                    dict_ev.Add(2, room.roomInfo);
                    SendToOther(24, dict_ev);

                    gamestate = GameState.ready;
                }
                else//如果房间没有空位，就重新创建
                {
                    room = new Room();

                    room.isKechi = isKeChi;

                Create: Random ran = new Random();
                    int roomname = ran.Next(100001, 1000000);

                    if (AllGames.dict_rooms_tongYongMJ_coin.ContainsKey(roomname))
                    {
                        goto Create;
                    }
                    else
                    {
                        room.RoomName = roomname;

                        room.desk_dong.isJoin = true;
                        room.desk_dong.peer = this;
                        joinDesk = room.desk_dong;

                        //赋值游戏级别（初级、中级、高级）
                        if (gameLevel == GameLevel.chuji)
                        {
                            room.roomInfo.gameLevel = GameLevel.chuji;
                            room.diFen = 500;
                        }
                        else if (gameLevel == GameLevel.zhongji)
                        {
                            room.roomInfo.gameLevel = GameLevel.zhongji;
                            room.diFen = 1000;
                        }

                        room.AllActorCount++;

                        player.playerPos = PlayerPosition.dong;
                        player.jiFen = 0;
                        player.actorId = room.AllActorCount;

                        room.masterClientID = player.actorId;//设置庄家ID

                        room.roomInfo.iskechi = isKeChi;
                        room.roomInfo.yuePaiJuShu = 0;
                        room.roomInfo.roomName = roomname;
                        room.roomInfo.isYuePai = false;
                        room.roomInfo.masterClientID = room.masterClientID;
                        room.roomInfo.gameLevel = gameLevel;

                        AllGames.dict_rooms_tongYongMJ_coin.Add(roomname, room);

                        Dictionary<short, object> dict_res = new Dictionary<short, object>();

                        dict_res.Add(1, room.roomInfo);

                        dict_res.Add(2, player);//把玩家的属性传出去

                        SendResponse(10, ReturnCode.success, dict_res);

                        gamestate = GameState.ready;
                    }
                }
            }
            else if(opCode==18)//每日领奖
            {
                bool canLingJinag = MySQLManager.UseIDfindLingJingMessage(userinfo.id);
                if (canLingJinag == false)
                {
                    int i = MySQLManager.UpdateCoin(50, userinfo.id);
                    if (i > 0)
                    {
                        int index=MySQLManager.UpdateIslingjiang(1, userinfo.id);
                        Console.WriteLine("更新领奖信息的事情"+index);
                        int currentCoin=MySQLManager.UseIDfindCoin(userinfo.id);
                        if (currentCoin > 0)
                        {
                            Dictionary<short, object> dict_res = new Dictionary<short, object>();
                            dict_res.Add(1, 50);
                            dict_res.Add(2, currentCoin);
                            dict_res.Add(3, true);
                            SendResponse(11, ReturnCode.success, dict_res);
                        }
                        else
                        {
                            Console.WriteLine("没找到金币信息");
                        }
                    }
                    else
                    {
                        Console.WriteLine("更新信息失败");
                    }
                }
                else
                {
                    Dictionary<short, object> dict_res = new Dictionary<short, object>();
                    dict_res.Add(1, 0);
                    dict_res.Add(2, 0);
                    dict_res.Add(3, false);
                    SendResponse(11, ReturnCode.success, dict_res);
                }
            }
            else if (opCode == 19)//排行榜请求
            {
                List<PaiHangData> list = MySQLManager.QueryPaiHang(10);
                int mingci = MySQLManager.QueryMyMingCi(userinfo.id);
                if (list.Count != 0)
                {
                    Dictionary<short, object> dict_res = new Dictionary<short, object>();
                    dict_res.Add(1, list);
                    dict_res.Add(2, mingci);
                    SendResponse(12, ReturnCode.success, dict_res);
                }
            }
            else if (opCode == 20) //请求获取玩家今天玩了多少场
            {
                bool canLingqvrenwu1 = MySQLManager.UseIDfindCanLingQvRenWu1(userinfo.id);
                bool canLingqvrenwu2 = MySQLManager.UseIDfindCanLingQvRenWu2(userinfo.id);
                bool canLingqvrenwu3 = MySQLManager.UseIDfindCanLingQvRenWu3(userinfo.id);
                int jinripipeijushu = MySQLManager.UseIDfindJinRiCoinJuShuMessage(userinfo.id);
                bool youLingQu = false;
                if (canLingqvrenwu1)
                {
                    if (jinripipeijushu >= 2)
                    {
                        youLingQu = true;
                    }
                }
                if (canLingqvrenwu2)
                {
                    if (jinripipeijushu >= 5)
                    {
                        youLingQu = true;
                    }
                }
                if (canLingqvrenwu3)
                {
                    if (jinripipeijushu >= 10)
                    {
                        youLingQu = true;
                    }
                }
                Dictionary<short, object> dict_res = new Dictionary<short, object>();
                dict_res.Add(1, youLingQu);
                SendResponse(13, ReturnCode.success, dict_res);
            }
            else if (opCode == 21) //玩家向服务器请求任务的相关数据
            {
                int jinripipeijushu = MySQLManager.UseIDfindJinRiCoinJuShuMessage(userinfo.id);
                int jinriyvepaijushu = MySQLManager.UseIDfindJinRiYvePaiJuShuMessage(userinfo.id);
                int jinrizongjushu = MySQLManager.UseIDfindJinRiZongJuShuMessage(userinfo.id);
                int zongjushu = MySQLManager.UseIDfindZongJuShuMessage(userinfo.id);
                bool canLingqvrenwu1 = MySQLManager.UseIDfindCanLingQvRenWu1(userinfo.id);
                bool canLingqvrenwu2 = MySQLManager.UseIDfindCanLingQvRenWu2(userinfo.id);
                bool canLingqvrenwu3 = MySQLManager.UseIDfindCanLingQvRenWu3(userinfo.id);
                Dictionary<short, object> dict_res = new Dictionary<short, object>();
                dict_res.Add(1, jinripipeijushu);
                dict_res.Add(2, jinriyvepaijushu);
                dict_res.Add(3, jinrizongjushu);
                dict_res.Add(4, zongjushu);
                dict_res.Add(5, canLingqvrenwu1);
                dict_res.Add(6, canLingqvrenwu2);
                dict_res.Add(7, canLingqvrenwu3);
                SendResponse(14, ReturnCode.success, dict_res);
            }
            else if (opCode == 22)//玩家完成任务点击了领取金币
            {
                int getcoin = Converter<int>(dict[1]);
                if (getcoin == 100)
                {
                    MySQLManager.UpdateCanLingQuRenwu1(1, userinfo.id);
                    List<PaiHangData> list = MySQLManager.QueryPaiHang(10);
                    int mingci = MySQLManager.QueryMyMingCi(userinfo.id);
                    if (list.Count != 0)
                    {
                        Dictionary<short, object> dict_res = new Dictionary<short, object>();
                        dict_res.Add(1, list);
                        dict_res.Add(2, mingci);
                        SendResponse(12, ReturnCode.success, dict_res);
                    }
                }
                else if (getcoin == 300)
                {
                    MySQLManager.UpdateCanLingQuRenwu2(1, userinfo.id);
                    List<PaiHangData> list = MySQLManager.QueryPaiHang(10);
                    int mingci = MySQLManager.QueryMyMingCi(userinfo.id);
                    if (list.Count != 0)
                    {
                        Dictionary<short, object> dict_res = new Dictionary<short, object>();
                        dict_res.Add(1, list);
                        dict_res.Add(2, mingci);
                        SendResponse(12, ReturnCode.success, dict_res);
                    }
                }
                else if (getcoin == 800)
                {
                    MySQLManager.UpdateCanLingQuRenwu3(1, userinfo.id);
                    List<PaiHangData> list = MySQLManager.QueryPaiHang(10);
                    int mingci = MySQLManager.QueryMyMingCi(userinfo.id);
                    if (list.Count != 0)
                    {
                        Dictionary<short, object> dict_res = new Dictionary<short, object>();
                        dict_res.Add(1, list);
                        dict_res.Add(2, mingci);
                        SendResponse(12, ReturnCode.success, dict_res);
                    }
                }
                MySQLManager.UpdateCoin(getcoin, userinfo.id);
            }
            else if (opCode == 23) //注册功能
            {
                string username = Converter<string>(dict[1]);
                string password = Converter<string>(dict[2]);
                bool IsUesrExit = MySQLManager.IsUserExit(username);
                if (IsUesrExit)
                {
                    SendResponse(15, ReturnCode.success, null);
                }
                else
                {
                    int Maxid=MySQLManager.GetMaxid();
                    MySQLManager.InsertNewData(Maxid + 1, username,password);
                    SendResponse(16, ReturnCode.success, null);
                }
            }
            else if (opCode == 24) //根据ID查询是否购买了音乐盒
            {
                bool IsMusic = MySQLManager.UseIDfindIsMusic(userinfo.id);
                Dictionary<short, object> dict_res = new Dictionary<short, object>();
                dict_res.Add(1, IsMusic);
                SendResponse(18, ReturnCode.success, dict_res);
            }
            else if (opCode == 25) //根据ID查询金币以及钻石数量
            {
                int coin = MySQLManager.UseIDfindCoin(userinfo.id);
                int diamond = MySQLManager.UseIDfindDiamond(userinfo.id);
                Dictionary<short, object> dict_res = new Dictionary<short, object>();
                dict_res.Add(1, coin);
                dict_res.Add(2, diamond);
                SendResponse(19, ReturnCode.success, dict_res);
            }
            else if (opCode == 26) //更新钱包
            {
                int costCoin= Converter<int>(dict[1]);
                string buyState= Converter<string>(dict[2]);
                if (buyState == "coin")
                {
                    MySQLManager.UpdateCoin(costCoin, userinfo.id);
                }
                else if (buyState == "diamond")
                {
                    MySQLManager.UpdateDiamond(costCoin, userinfo.id);
                }
            }
            else if (opCode == 27) //更新音乐盒
            {
                int IsMusic = Converter<int>(dict[1]);
                MySQLManager.UpdateIsMusic(IsMusic, userinfo.id);
                MySQLManager.UpdateDiamond(-12, userinfo.id);
            }
        }
        public void SendToOther(short opcode,Dictionary<short, object> dict_ev)
        {
            if (player.playerPos == PlayerPosition.dong)
            {
                if (room.desk_nan.isJoin)
                {
                    room.desk_nan.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_xi.isJoin)
                {
                    room.desk_xi.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_bei.isJoin)
                {
                    room.desk_bei.peer.SendEvent(opcode, dict_ev);
                }

            }
            else if (player.playerPos == PlayerPosition.nan)
            {
                if (room.desk_xi.isJoin)
                {
                    room.desk_xi.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_bei.isJoin)
                {
                    room.desk_bei.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_dong.isJoin)
                {
                    room.desk_dong.peer.SendEvent(opcode, dict_ev);
                }
            }
            else if (player.playerPos == PlayerPosition.xi)
            {

                if (room.desk_bei.isJoin)
                {
                    room.desk_bei.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_dong.isJoin)
                {
                    room.desk_dong.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_nan.isJoin)
                {
                    room.desk_nan.peer.SendEvent(opcode, dict_ev);
                }
            }
            else if (player.playerPos == PlayerPosition.bei)
            {
                if (room.desk_dong.isJoin)
                {
                    room.desk_dong.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_nan.isJoin)
                {
                    room.desk_nan.peer.SendEvent(opcode, dict_ev);
                }
                if (room.desk_xi.isJoin)
                {
                    room.desk_xi.peer.SendEvent(opcode, dict_ev);
                }
            }
        }
        public T Converter<T>(object o)
        {
            string str = JsonConvert.SerializeObject(o);
            T t1 = JsonConvert.DeserializeObject<T>(str);
            return t1;
        }
        void SendEventToAll(short eventcode, Dictionary<short, object> dict)
        {
            if (room != null)
            {
                for (int i = 0; i < room.desklist.Count; i++)
                {
                    if (room.desklist[i].peer != null && room.desklist[i].peer.IsConnected)
                    {
                        room.desklist[i].peer.SendEvent(eventcode, dict);
                    }
                }
            }
        }
    }
}
